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

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

#include "httpparser_p.h"
#include <QtCore/QList>

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Functions

ParseStatus Sonde::Http::anonymous_namespace{httpparser.cpp}::readSizedBody (const QByteArray &buffer, qsizetype bodyStart, const ParseLimits &limits, Request *req, qsizetype *consumed, int *errorStatus)
 Reads a body by Content-Length (no header means an empty body).
ParseStatus Sonde::Http::anonymous_namespace{httpparser.cpp}::readChunkedBody (const QByteArray &buffer, qsizetype bodyStart, const ParseLimits &limits, Request *req, qsizetype *consumed, int *errorStatus)
 Reads a chunked body.
qsizetype Sonde::Http::anonymous_namespace{httpparser.cpp}::endOfTrailers (const QByteArray &buffer, qsizetype pos)
 Skips the trailer section after the last chunk, which starts at pos.
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.
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.
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.

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.