QHttpEngine 1.0.1
Simple and secure HTTP server for Qt applications
Loading...
Searching...
No Matches
parser.h
1/*
2 * Copyright (c) 2017 Nathan Osman
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
21 */
22
23#ifndef QHTTPENGINE_PARSER_H
24#define QHTTPENGINE_PARSER_H
25
26#include <QList>
27
28#include <qhttpengine/socket.h>
29
30#include "qhttpengine_export.h"
31
32namespace QHttpEngine
33{
34
42class QHTTPENGINE_EXPORT Parser
43{
44public:
45
57 static void split(const QByteArray &data, const QByteArray &delim, int maxSplit, QByteArrayList &parts);
58
62 static bool parsePath(const QByteArray &rawPath, QString &path, Socket::QueryStringMap &queryString);
63
70 static bool parseHeaderList(const QList<QByteArray> &lines, Socket::HeaderMap &headers);
71
79 static bool parseHeaders(const QByteArray &data, QList<QByteArray> &parts, Socket::HeaderMap &headers);
80
84 static bool parseRequestHeaders(const QByteArray &data, Socket::Method &method, QByteArray &path, Socket::HeaderMap &headers);
85
89 static bool parseResponseHeaders(const QByteArray &data, int &statusCode, QByteArray &statusReason, Socket::HeaderMap &headers);
90};
91
92}
93
94#endif // QHTTPENGINE_PARSER_H
Utility methods for parsing HTTP requests and responses.
Definition parser.h:43
static bool parseHeaderList(const QList< QByteArray > &lines, Socket::HeaderMap &headers)
Parse a list of lines containing HTTP headers.
static bool parseRequestHeaders(const QByteArray &data, Socket::Method &method, QByteArray &path, Socket::HeaderMap &headers)
Parse HTTP request headers.
static bool parsePath(const QByteArray &rawPath, QString &path, Socket::QueryStringMap &queryString)
Parse and remove the query string from a path.
static bool parseResponseHeaders(const QByteArray &data, int &statusCode, QByteArray &statusReason, Socket::HeaderMap &headers)
Parse HTTP response headers.
static void split(const QByteArray &data, const QByteArray &delim, int maxSplit, QByteArrayList &parts)
Split a QByteArray by the provided delimiter.
static bool parseHeaders(const QByteArray &data, QList< QByteArray > &parts, Socket::HeaderMap &headers)
Parse HTTP headers.
Method
Definition socket.h:122
QMultiMap< QString, QString > QueryStringMap
Map consisting of query string values.
Definition socket.h:105
QMultiMap< IByteArray, QByteArray > HeaderMap
Map consisting of HTTP headers.
Definition socket.h:114