Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
httpparser_p.h File Reference

HTTP/1.1 request parsing for the HTTP transport. More...

#include <QtCore/QByteArray>
#include <QtCore/QHash>

Go to the source code of this file.

Classes

struct  Sonde::Http::Request
 A parsed HTTP request. More...
struct  Sonde::Http::ParseLimits
 Size limits applied while parsing. More...

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Enumerations

enum class  Sonde::Http::ParseStatus { Incomplete , Complete , Error }
 Result of trying to parse a request from the front of a buffer. More...

Functions

ParseStatus Sonde::Http::parseRequest (QByteArray *buffer, const ParseLimits &limits, Request *request, int *errorStatus)
 Parses one request from the front of buffer, and removes it when complete.
bool Sonde::Http::parseHead (const QByteArray &head, Request *request)
 Parses the request line and headers.
qsizetype Sonde::Http::decodeChunked (const QByteArray &buffer, qsizetype from, qsizetype maxBody, QByteArray *out)
 Decodes a chunked body that starts at from in buffer.
QByteArray Sonde::Http::reasonPhrase (int status)
 The reason phrase of an HTTP status code, e.g. "Not Found".
bool Sonde::Http::bearerTokenMatches (const QByteArray &authorization, const QByteArray &token)
 Whether an Authorization header carries Bearer <token>.

Detailed Description

HTTP/1.1 request parsing for the HTTP transport.

Internal; split out from the transport so it can be unit-tested and fuzzed without sockets.

Enumeration Type Documentation

◆ ParseStatus

enum class Sonde::Http::ParseStatus
strong

Result of trying to parse a request from the front of a buffer.

Enumerator
Incomplete 

More data is needed.

Complete 

A request was parsed and removed from the buffer.

Error 

The data is malformed or too large; respond with the given status and close.

Function Documentation

◆ bearerTokenMatches()

bool Sonde::Http::bearerTokenMatches ( const QByteArray & authorization,
const QByteArray & token )

Whether an Authorization header carries Bearer <token>.

Compares in time that depends only on the lengths, not on how much of the token matches, so the token can't be guessed byte by byte from timing.

◆ decodeChunked()

qsizetype Sonde::Http::decodeChunked ( const QByteArray & buffer,
qsizetype from,
qsizetype maxBody,
QByteArray * out )

Decodes a chunked body that starts at from in buffer.

Returns
The number of bytes used (counted from from), 0 if more data is needed, or -1 if the body is malformed or larger than maxBody.

◆ parseHead()

bool Sonde::Http::parseHead ( const QByteArray & head,
Request * request )

Parses the request line and headers.

Returns
False if the request line is malformed.

◆ parseRequest()

ParseStatus Sonde::Http::parseRequest ( QByteArray * buffer,
const ParseLimits & limits,
Request * request,
int * errorStatus )

Parses one request from the front of buffer, and removes it when complete.

Parameters
bufferReceived bytes.
limitsSize limits.
requestReceives the request.
errorStatusReceives the HTTP status to respond with on ParseStatus::Error.