Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::HttpParser Struct Reference

Incremental HTTP request or response parser. More...

#include <HttpParser.h>

Public Types

enum class  Method {
  HttpGET ,
  HttpPUT ,
  HttpPOST
}
 Method of the current request / response. More...
 
enum class  State {
  Parsing ,
  Result ,
  Finished
}
 State of the parser. More...
 
enum class  Result {
  Method ,
  Url ,
  Version ,
  HeaderName ,
  HeaderValue ,
  HeadersEnd ,
  StatusCode ,
  StatusString ,
  Body
}
 One possible Result reported by the parser. More...
 
enum class  Type {
  Request ,
  Response
}
 Type of the stream to be parsed (Request or Response) More...
 
enum class  HeaderType { ContentLength = 0 }
 Header types. More...
 

Public Member Functions

SC::Result parse (Span< const char > data, size_t &readBytes, Span< const char > &parsedData)
 Parse an incoming chunk of bytes, returning actually parsed span. More...
 
bool matchesHeader (HeaderType headerName) const
 Check if current result matches this HeaderType. More...
 

Public Attributes

Method method = Method::HttpGET
 Http method. More...
 
size_t tokenStart = 0
 Offset in bytes to start of parsed token. More...
 
size_t tokenLength = 0
 Length in bytes of parsed token. More...
 
uint32_t statusCode = 0
 Parsed http status code. More...
 
uint64_t contentLength = 0
 Content-Length of http request. More...
 
Result result = Result::HeadersEnd
 Last found result. More...
 
State state = State::Parsing
 Current state of the parser. More...
 
Type type = Type::Request
 Type of http stream (request or response) More...
 

Detailed Description

Incremental HTTP request or response parser.

Member Enumeration Documentation

◆ HeaderType

enum class SC::HttpParser::HeaderType
strong

Header types.

Enumerator
ContentLength 

Content-Length header.

◆ Method

enum class SC::HttpParser::Method
strong

Method of the current request / response.

Enumerator
HttpGET 

GET method

HttpPUT 

PUT method

HttpPOST 

POST method

◆ Result

enum class SC::HttpParser::Result
strong

One possible Result reported by the parser.

Enumerator
Method 

Http method has been found.

Url 

Http url has been found.

Version 

Http version number has been found.

HeaderName 

Name of an http header has been found.

HeaderValue 

Value of an http header has been found.

HeadersEnd 

Lash http header has been found.

StatusCode 

Http status code has been found.

StatusString 

Http status string has been found.

Body 

Start of http body has been found.

◆ State

enum class SC::HttpParser::State
strong

State of the parser.

Enumerator
Parsing 

Parser is parsing.

Result 

Parser is reporting a result.

Finished 

Parser has finished.

◆ Type

enum class SC::HttpParser::Type
strong

Type of the stream to be parsed (Request or Response)

Enumerator
Request 

Stream to be parsed is an Http request from a client.

Response 

Stream to be parsed is an http response from a server.

Member Function Documentation

◆ matchesHeader()

bool SC::HttpParser::matchesHeader ( HeaderType  headerName) const

Check if current result matches this HeaderType.

◆ parse()

SC::Result SC::HttpParser::parse ( Span< const char >  data,
size_t readBytes,
Span< const char > &  parsedData 
)

Parse an incoming chunk of bytes, returning actually parsed span.

Parameters
dataIncoming chunk of bytes to be parsed
readBytesNumber of bytes actually read
parsedDataA sub-span of data pointing at the actually parsed data
Returns
Valid result if parse didn't encounter any error

Member Data Documentation

◆ contentLength

uint64_t SC::HttpParser::contentLength = 0

Content-Length of http request.

◆ method

Method SC::HttpParser::method = Method::HttpGET

Http method.

◆ result

Result SC::HttpParser::result = Result::HeadersEnd

Last found result.

◆ state

State SC::HttpParser::state = State::Parsing

Current state of the parser.

◆ statusCode

uint32_t SC::HttpParser::statusCode = 0

Parsed http status code.

◆ tokenLength

size_t SC::HttpParser::tokenLength = 0

Length in bytes of parsed token.

◆ tokenStart

size_t SC::HttpParser::tokenStart = 0

Offset in bytes to start of parsed token.

◆ type

Type SC::HttpParser::type = Type::Request

Type of http stream (request or response)


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