src/__unused/t_htp_str.c
static size_t
t_htp_str_formHeader( lua_State *L, luaL_Buffer *lB, struct t_htp_str *s,
	int code, const char *msg, int len, int t )
{
	size_t   c;       ///< count all chars added in this method
	size_t   bs;      ///< chars added currently to buffers
	char    *b = luaL_prepbuffer( lB );

	if (len)
	{
		bs = sprintf( b,
			"HTTP/1.1 %d %s\r\n"
			"Connection: %s\r\n"
			"Date: %s\r\n"
			"Content-Length: %d\r\n"
			"%s",
			(int) code,                                 // HTTP Status code
			(NULL == msg) ? t_htp_status( code ) : msg, // HTTP Status Message
			(s->con->kpAlv) ? "Keep-Alive" : "Close",   // Keep-Alive or close
			s->con->srv->fnw,                           // Formatted Date
			len,                                        // Content-Length
			(t) ? "" : "\r\n"
			);
		s->rsCl = len;
	}
	else
	{
		bs = sprintf( b,
			"HTTP/1.1 %d %s\r\n"
			"Connection: %s\r\n"
			"Date: %s\r\n"
			"Transfer-Encoding: chunked\r\n"
			"%s",
			(int) code,                                 // HTTP Status code
			(NULL == msg) ? t_htp_status( code ) : msg, // HTTP Status Message
			(s->con->kpAlv) ? "Keep-Alive" : "Close",   // Keep-Alive or close
			s->con->srv->fnw,                           // Formatted Date
			(t) ? "" : "\r\n"
			);
		s->rsCl = len;
	}
	luaL_addsize( lB, bs );
	// TODO: Find a way to deal more efficiently with that buffer
	b  = luaL_prepbuffer( lB );
	c  = bs;
	bs = 0;
	if (t)
	{
		lua_pushnil( L );
		while (lua_next( L, t ))
		{
			bs += sprintf( b,
				"%s: %s\r\n",
				lua_tostring( L, -2 ),
				lua_tostring( L, -1 )
				);
			lua_pop( L, 1 );      //FIXME:  this can't pop, it must remove
		}
		bs += sprintf( b, "\r\n" );   // finish off the HTTP Headers part
		luaL_addsize( lB, bs );
	}
	c += bs;
	s->rsBl = (len) ? c + len : 0;
	return c;
}
/**-----------------------------------------------------------------------------
 * Form HTTP response Header.
 * \param  L        The lua state.
 * \param  luaL_Buffer  Lua Buffer pointer.
 * \param  struct t_htp_str struct pointer.
 * \param  int          the HTTP Status Code to be returned.
 * \param  char*        the HTTP Status Message to be returned.
 * \param  size_t*      length of the HTTP Payload aka. Content-length.
 * \param  int          position of table on stack where headers are present.
 *                      0 means no additional headers.
 * \return  int         size of string added to the buffer.
 * ---------------------------------------------------------------------------*/
Form HTTP response Header.
\param  L        The lua state.
\param  luaL_Buffer  Lua Buffer pointer.
\param  struct t_htp_str struct pointer.
\param  int          the HTTP Status Code to be returned.
\param  char*        the HTTP Status Message to be returned.
\param  size_t*      length of the HTTP Payload aka. Content-length.
\param  int          position of table on stack where headers are present.
0 means no additional headers.
\return  int         size of string added to the buffer.
Form HTTP response Header . \ param L The lua state . \ param luaL_Buffer Lua Buffer pointer . \ param struct t_htp_str struct pointer . \ param int the HTTP Status Code to be returned . \ param char * the HTTP Status Message to be returned . \ param size_t * length of the HTTP Payload aka . Content - length . \ param int position of table on stack where headers are present . 0 means no additional headers . \ return int size of string added to the buffer .
static size_t
t_htp_str_formHeader( lua_State *L, luaL_Buffer *lB, struct t_htp_str *s,
	int code, const char *msg, int len, int t )
{
	size_t   c;       
	size_t   bs;      
	char    *b = luaL_prepbuffer( lB );
	if (len)
	{
		bs = sprintf( b,
			"HTTP/1.1 %d %s\r\n"
			"Connection: %s\r\n"
			"Date: %s\r\n"
			"Content-Length: %d\r\n"
			"%s",
			(int) code,                                 
			(NULL == msg) ? t_htp_status( code ) : msg, 
			(s->con->kpAlv) ? "Keep-Alive" : "Close",   
			s->con->srv->fnw,                           
			len,                                        
			(t) ? "" : "\r\n"
			);
		s->rsCl = len;
	}
	else
	{
		bs = sprintf( b,
			"HTTP/1.1 %d %s\r\n"
			"Connection: %s\r\n"
			"Date: %s\r\n"
			"Transfer-Encoding: chunked\r\n"
			"%s",
			(int) code,                                 
			(NULL == msg) ? t_htp_status( code ) : msg, 
			(s->con->kpAlv) ? "Keep-Alive" : "Close",   
			s->con->srv->fnw,                           
			(t) ? "" : "\r\n"
			);
		s->rsCl = len;
	}
	luaL_addsize( lB, bs );
	b  = luaL_prepbuffer( lB );
	c  = bs;
	bs = 0;
	if (t)
	{
		lua_pushnil( L );
		while (lua_next( L, t ))
		{
			bs += sprintf( b,
				"%s: %s\r\n",
				lua_tostring( L, -2 ),
				lua_tostring( L, -1 )
				);
			lua_pop( L, 1 );      
		}
		bs += sprintf( b, "\r\n" );   
		luaL_addsize( lB, bs );
	}
	c += bs;
	s->rsBl = (len) ? c + len : 0;
	return c;
}
static size_t t_htp_str_formHeader ( lua_State * L , luaL_Buffer * lB , struct t_htp_str * s , int code , const char * msg , int len , int t ) { size_t c ; size_t bs ; char * b = luaL_prepbuffer ( lB ) ; if ( len ) { bs = sprintf ( b , " \r \n " " \r \n " " \r \n " " \r \n " " " , ( int ) code , ( NULL == msg ) ? t_htp_status ( code ) : msg , ( s -> con -> kpAlv ) ? " " : " " , s -> con -> srv -> fnw , len , ( t ) ? " " : " \r \n " ) ; s -> rsCl = len ; } else { bs = sprintf ( b , " \r \n " " \r \n " " \r \n " " \r \n " " " , ( int ) code , ( NULL == msg ) ? t_htp_status ( code ) : msg , ( s -> con -> kpAlv ) ? " " : " " , s -> con -> srv -> fnw , ( t ) ? " " : " \r \n " ) ; s -> rsCl = len ; } luaL_addsize ( lB , bs ) ; b = luaL_prepbuffer ( lB ) ; c = bs ; bs = 0 ; if ( t ) { lua_pushnil ( L ) ; while ( lua_next ( L , t ) ) { bs += sprintf ( b , " \r \n " , lua_tostring ( L , -2 ) , lua_tostring ( L , -1 ) ) ; lua_pop ( L , 1 ) ; } bs += sprintf ( b , " \r \n " ) ; luaL_addsize ( lB , bs ) ; } c += bs ; s -> rsBl = ( len ) ? c + len : 0 ; return c ; }
Form HTTP response Header.
Form HTTP response Header .
///< count all chars added in this method ///< chars added currently to buffers // HTTP Status code // HTTP Status Message // Keep-Alive or close // Formatted Date // Content-Length // HTTP Status code // HTTP Status Message // Keep-Alive or close // Formatted Date // TODO: Find a way to deal more efficiently with that buffer //FIXME:  this can't pop, it must remove // finish off the HTTP Headers part