#include <ScgiRequestParser.h>
Public Types | |
enum | ErrorReason { , LENGTH_STRING_TOO_LARGE, LIMIT_REACHED, INVALID_LENGTH_STRING, HEADER_TERMINATOR_EXPECTED, INVALID_HEADER_DATA } |
Public Member Functions | |
ScgiRequestParser (unsigned long maxSize=0) | |
Create a new ScgiRequestParser, ready to parse a request. | |
unsigned int | feed (const char *data, unsigned int size) |
Feed SCGI request data to the parser. | |
string | getHeaderData () const |
Get the raw header data that has been processed so far. | |
StaticString | getHeader (const StaticString &name) const |
Get the value of the header with the given name. | |
bool | hasHeader (const StaticString &name) const |
Checks whether there is a header with the given name. | |
State | getState () const |
Get the parser's current state. | |
ErrorReason | getErrorReason () const |
Returns the reason why the parser entered the error state. | |
bool | acceptingInput () const |
Checks whether this parser is still capable of accepting input (that is, that this parser is not in a final state). |
It parses the request header and ignores the body data.
You can use it by constructing a parser object, then feeding data to the parser until it has reached a final state.
Example:
ScgiRequestParser parser; char buf[1024 * 16]; ssize_t size; unsigned in bytesAccepted; do { size = read(fd, buf, sizeof(buf)); bytesAccepted = parser.feed(buf, size); } while (parser.acceptingInput()); // Parser is done when its return value isn't equal to the input size. // Check whether a parse error occured. if (parser.getState() == ScgiRequestParser::ERROR) { bailOut(); } else { // All good! Do something with the SCGI header that the parser parsed. processHeader(parser.getHeaderData()); // If the last buffer passed to the parser also contains body data, // then the body data starts at 'buf + bytesAccepted'. if (bytesAccepted < size) { processBody(buf + bytesAccepted); } while (!end_of_file(fd)) { ... read(...) ... processBody(...); } }
Parser properties:
Passenger::ScgiRequestParser::ScgiRequestParser | ( | unsigned long | maxSize = 0 |
) | [inline] |
Create a new ScgiRequestParser, ready to parse a request.
maxSize | The maximum size that the SCGI data is allowed to be, or 0 if no limit is desired. |
unsigned int Passenger::ScgiRequestParser::feed | ( | const char * | data, | |
unsigned int | size | |||
) | [inline] |
Feed SCGI request data to the parser.
data | The data to feed. | |
size | The size of the data, in bytes. |
if result <= size: getState() == DONE || getState() == ERROR
ErrorReason Passenger::ScgiRequestParser::getErrorReason | ( | ) | const [inline] |
StaticString Passenger::ScgiRequestParser::getHeader | ( | const StaticString & | name | ) | const [inline] |
Get the value of the header with the given name.
Lookup is case-sensitive.
Returns the empty string if there is no such header.
bool Passenger::ScgiRequestParser::hasHeader | ( | const StaticString & | name | ) | const [inline] |
Checks whether there is a header with the given name.
Lookup is case-sensitive.