Passenger::HttpStatusExtractor Class Reference

Utility class for extracting the HTTP status value from an HTTP response. More...

#include <HttpStatusExtractor.h>

List of all members.

Public Member Functions

bool feed (const char *data, unsigned int size)
 Feed HTTP response data to this HttpStatusExtractor.
string getStatusLine () const
 Returns the HTTP status line that has been determined.
string getBuffer () const
 Get the data that has been fed so far.

Detailed Description

Utility class for extracting the HTTP status value from an HTTP response.

This class is used for generating a proper HTTP response. The response data that Passenger backend processes generate are like CGI responses, and do not include an initial "HTTP/1.1 [status here]" line, so this class used to extract the status from the response in order to generate a proper initial HTTP response line.

This class is supposed to be used as follows:

This class will also ensure that the status line contains a status text, e.g. if the HTTP data's status value is only "200" then "OK" will be automatically appended.

Note:
When the API documentation for this class refers to "\r\n", we actually mean "\x0D\x0A" (the HTTP line termination string). "\r\n" is only written out of convenience.

Member Function Documentation

bool Passenger::HttpStatusExtractor::feed ( const char *  data,
unsigned int  size 
) [inline]

Feed HTTP response data to this HttpStatusExtractor.

One is to keep feeding data until this method returns true. When a sufficient amount of data has been fed, this method will extract the status line from the data that has been fed so far, and return true.

Do not call this method again once it has returned true.

It is safe to feed excess data. That is, it is safe if the 'data' argument contains a part of the HTTP response body. HttpStatusExtractor will only look for the status line in the HTTP response header, not in the HTTP response body. All fed data is buffered and will be available via getBuffer(), so no data will be lost.

Returns:
Whether the HTTP status has been extracted yet.
Precondition:
feed() did not previously return true.
data != NULL
size > 0
string Passenger::HttpStatusExtractor::getStatusLine (  )  const [inline]

Returns the HTTP status line that has been determined.

The default value is "200 OK\r\n", which is returned if the HTTP response data that has been fed so far does not include a status line.

Note:
The return value includes a trailing CRLF, e.g. "404 Not Found\r\n".

The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2