Ns_ConnFlushHeaders3aolserver
Routines to construct send http response headers
Part of Ns_ConnQueueHeaders(3aolserver).
Usage
void
void
Arguments
- Ns_Conn conn (in)
-
Pointer to open connection.
- int status (in)
-
HTTP response status.
Overview
These function format headers pending in the outputheaders Ns_Set of the given conn Ns_Conn structure to be sent to the client. The headers data along with a preceeding HTTP response line with the given status code (e.g., "HTTP/1.1 200 OK") is formatted as a single string with 0fR separators between header key: value pairs and a trailing 0fR to indicate end of headers.
- int
Ns_ConnFlushHeaders(conn) -
This routine constructs the headers and then attempts to send them immediately to the client. The result is either NS_OK if the content was sent, NS_ERROR otherwise.
- void
Ns_ConnQueueHeaders(conn) -
This routine constructs the headers as with
Ns_ConnFlushHeadersbut does not send the data to the client. Instead, the resulting headers string is stored in an internal buffer to be sent later on the first call toNs_ConnSend. Delaying the flush of the content helps increase performance by providing the opportunity to combine the headers and content responses into a single system call.
Note that higher level routines which generate complete responses such as the Ns_ConnReturn routines or Ns_ConnFlush call Ns_ConnQueueHeaders automatically as needed. Only custom code which constructs headers manually and sends content directly must include a call to Ns_ConnQueueHeaders or Ns_ConnFlushHeaders before generating the output content.
Examples
The following example demonstrates a simple response. In this case, the headers are queued and sent with the small "hello" message on the call to Ns_ConnPuts which internally calls Ns_ConnSend:
Ns_ConnSetRequiredHeaders(conn, "text/plain", 5); Ns_ConnQueueHeaders(conn, 200); Ns_ConnPuts(conn, "hello");
Keywords
connection, headers