Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
httpparser_p.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <QtCore/QByteArray>
8#include <QtCore/QHash>
9
10namespace Sonde::Http {
11
13struct Request
14{
15 QByteArray method;
16 QByteArray target;
17 QByteArray path;
18 QByteArray version;
19 QHash<QByteArray, QByteArray> headers;
20 QByteArray body;
21 bool keepAlive = true;
22
24 QByteArray header(const char *name) const { return headers.value(QByteArray(name)); }
25};
26
29{
30 qsizetype maxHeaderBytes = qsizetype{ 64 } * 1024;
31 qsizetype maxBodyBytes = qsizetype{ 4 } * 1024 * 1024;
32};
33
40
46ParseStatus parseRequest(QByteArray *buffer, const ParseLimits &limits, Request *request,
47 int *errorStatus);
48
50bool parseHead(const QByteArray &head, Request *request);
51
55qsizetype decodeChunked(const QByteArray &buffer, qsizetype from, qsizetype maxBody,
56 QByteArray *out);
57
59QByteArray reasonPhrase(int status);
60
65bool bearerTokenMatches(const QByteArray &authorization, const QByteArray &token);
66
67} // namespace Sonde::Http
ParseStatus
Result of trying to parse a request from the front of a buffer.
Definition httpparser_p.h:35
@ Incomplete
More data is needed.
Definition httpparser_p.h:36
@ Complete
A request was parsed and removed from the buffer.
Definition httpparser_p.h:37
Why something failed.
Definition expected.h:42
Size limits applied while parsing.
Definition httpparser_p.h:29
qsizetype maxBodyBytes
Decoded body (413 beyond).
Definition httpparser_p.h:31
qsizetype maxHeaderBytes
Request line and headers (431 beyond).
Definition httpparser_p.h:30
A parsed HTTP request.
Definition httpparser_p.h:14
QByteArray header(const char *name) const
A header value by lower-case name (empty if absent).
Definition httpparser_p.h:24
QHash< QByteArray, QByteArray > headers
Header fields; names lower-cased.
Definition httpparser_p.h:19
bool keepAlive
Whether the connection stays open after the response.
Definition httpparser_p.h:21
QByteArray method
Upper-cased method, e.g. "POST".
Definition httpparser_p.h:15
QByteArray body
Decoded body.
Definition httpparser_p.h:20
QByteArray target
Request target including any query string.
Definition httpparser_p.h:16
QByteArray path
Target without the query string.
Definition httpparser_p.h:17
QByteArray version
HTTP version, e.g. "HTTP/1.1".
Definition httpparser_p.h:18