TSHttpParserCreate¶
Parse HTTP headers from memory buffers.
Synopsis¶
#include <ts/ts.h>
-
TSHttpParser TSHttpParserCreate(void)¶
-
void TSHttpParserClear(TSHttpParser parser)¶
-
void TSHttpParserDestroy(TSHttpParser parser)¶
-
TSParseResult TSHttpHdrParseReq(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char **start, const char *end)¶
-
TSParseResult TSHttpHdrParseResp(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char **start, const char *end)¶
Description¶
TSHttpParserCreate()
creates an HTTP parser object. The
parser’s data structure contains information about the header being
parsed. A single HTTP parser can be used multiple times, though not
simultaneously. Before being used again, the parser must be cleared
by calling TSHttpParserClear()
.
TSHttpHdrParseReq()
parses an HTTP request header. The HTTP
header offset must already be created, and must reside
inside the marshal buffer bufp. The start argument
points to the current position of the string buffer being parsed
and the end argument points to one byte after the end of
the buffer to be parsed. On return, start is modified to
point past the last character parsed.
It is possible to parse an HTTP request header a single byte at a
time using repeated calls to TSHttpHdrParseReq()
. As long as
an error does not occur, the TSHttpHdrParseReq()
function
will consume that single byte and ask for more. TSHttpHdrParseReq()
should be called after TS_HTTP_READ_REQUEST_HDR_HOOK
.
TSHttpHdrParseResp()
operates in the same manner as
TSHttpHdrParseReq()
except it parses an HTTP response header.
It should be called after TS_HTTP_READ_RESPONSE_HDR_HOOK
.
TSHttpParserClear()
clears the specified HTTP parser so it
may be used again.
TSHttpParserDestroy()
destroys the TSHttpParser object pointed
to by parser. The parser pointer must not be nullptr.
Return Values¶
TSHttpHdrParseReq()
and TSHttpHdrParseResp()
both return
a TSParseResult
value. TS_PARSE_ERROR
is returned
on error, TS_PARSE_CONT
is returned if parsing of the header
stopped because the end of the buffer was reached, and
TS_PARSE_DONE
when a \r\n\r\n pattern is encountered,
indicating the end of the header.
See Also¶
TSAPI(3ts)