4#include "../Foundation/Result.h"
5#include "../Foundation/Span.h"
82 size_t globalStart = 0;
83 size_t globalLength = 0;
84 int topLevelCoroutine = 0;
85 int nestedParserCoroutine = 0;
86 bool parsedContentLength =
false;
87 size_t matchIndex = 0;
89 static constexpr size_t numMatches = 1;
91 size_t matchingHeader[numMatches] = {0};
92 bool matchingHeaderValid[numMatches] = {
false};
95 [[nodiscard]]
bool parseHeaderName(
char currentChar);
96 [[nodiscard]]
bool parseHeaderValue(
char currentChar);
97 [[nodiscard]]
bool parseStatusCode(
char currentChar);
98 [[nodiscard]]
bool parseNumberValue(
char currentChar);
99 [[nodiscard]]
bool parseHeadersEnd(
char currentChar);
100 [[nodiscard]]
bool parseMethod(
char currentChar);
101 [[nodiscard]]
bool parseUrl(
char currentChar);
103 template <
bool spaces>
104 [[nodiscard]]
bool parseVersion(
char currentChar);
106 template <
bool (HttpParser::*Func)(
char), Result currentResult>
107 [[nodiscard]]
SC::Result process(Span<const char>& data,
size_t& readBytes, Span<const char>& parsedData);
#define SC_COMPILER_EXPORT
Macro for symbol visibility in non-MSVC compilers.
Definition: Compiler.h:78
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition: PrimitiveTypes.h:42
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition: PrimitiveTypes.h:38
Incremental HTTP request or response parser.
Definition: HttpParser.h:17
Type type
Type of http stream (request or response)
Definition: HttpParser.h:63
SC::Result parse(Span< const char > data, size_t &readBytes, Span< const char > &parsedData)
Parse an incoming chunk of bytes, returning actually parsed span.
State
State of the parser.
Definition: HttpParser.h:34
@ Parsing
Parser is parsing.
@ Result
Parser is reporting a result.
@ Finished
Parser has finished.
size_t tokenStart
Offset in bytes to start of parsed token.
Definition: HttpParser.h:27
Method method
Http method.
Definition: HttpParser.h:25
Result
One possible Result reported by the parser.
Definition: HttpParser.h:42
@ Url
Http url has been found.
@ HeaderName
Name of an http header has been found.
@ StatusString
Http status string has been found.
@ Version
Http version number has been found.
@ HeaderValue
Value of an http header has been found.
@ Method
Http method has been found.
@ StatusCode
Http status code has been found.
@ Body
Start of http body has been found.
@ HeadersEnd
Lash http header has been found.
State state
Current state of the parser.
Definition: HttpParser.h:55
Result result
Last found result.
Definition: HttpParser.h:54
HeaderType
Header types.
Definition: HttpParser.h:74
@ ContentLength
Content-Length header.
Method
Method of the current request / response.
Definition: HttpParser.h:20
uint32_t statusCode
Parsed http status code.
Definition: HttpParser.h:29
size_t tokenLength
Length in bytes of parsed token.
Definition: HttpParser.h:28
Type
Type of the stream to be parsed (Request or Response)
Definition: HttpParser.h:59
@ Request
Stream to be parsed is an Http request from a client.
@ Response
Stream to be parsed is an http response from a server.
bool matchesHeader(HeaderType headerName) const
Check if current result matches this HeaderType.
uint64_t contentLength
Content-Length of http request.
Definition: HttpParser.h:30
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition: Result.h:11
View over a contiguous sequence of items (pointer + size in elements).
Definition: Span.h:20