Ns_ConnFlushHeaders(3) Routines to construct send HTTP response headers

Other Alias

Ns_ConnQueueHeaders

SYNOPSIS

#include "ns.h"



void
Ns_ConnFlushHeaders(conn, status)


void
Ns_ConnQueueHeaders(conn, status)

ARGUMENTS

Ns_Conn    conn    (in)
Pointer to open connection.
int    status    (in)
HTTP response status.


DESCRIPTION

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 fR separators between header key: value pairs and a trailing fR 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_ConnFlushHeaders but 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 to Ns_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