18 #ifndef NURIA_HTTPCLIENT_HPP
19 #define NURIA_HTTPCLIENT_HPP
21 #include "httppostbodyreader.hpp"
22 #include "network_global.hpp"
23 #include <QNetworkCookie>
24 #include <QHostAddress>
32 class HttpClientPrivate;
92 class NURIA_NETWORK_EXPORT
HttpClient :
public QIODevice {
125 AllVerbs = GET | POST | HEAD | PUT | DELETE
128 Q_DECLARE_FLAGS(HttpVerbs, HttpVerb)
138 HeaderCacheControl = 0,
149 HeaderAcceptEncoding,
150 HeaderAcceptLanguage,
159 HeaderContentEncoding = 2000,
160 HeaderContentLanguage,
161 HeaderContentDisposition,
166 HeaderTransferEncoding,
193 static QByteArray httpStatusCodeName (
int code);
198 static QByteArray httpHeaderName (
HttpHeader header);
201 bool isHeaderReady ()
const;
208 bool responseHeaderSent ()
const;
220 bool hasRequestHeader (
const QByteArray &key)
const;
223 bool hasRequestHeader (
HttpHeader header)
const;
232 QByteArray requestHeader (
const QByteArray &key)
const;
235 QByteArray requestHeader (
HttpHeader header)
const;
243 QList< QByteArray > requestHeaders (
const QByteArray &key)
const;
246 QList< QByteArray > requestHeaders (
HttpHeader header)
const;
249 const HeaderMap &requestHeaders ()
const;
252 bool hasResponseHeader (
const QByteArray &key)
const;
255 bool hasResponseHeader (
HttpHeader header)
const;
260 const HeaderMap &responseHeaders ()
const;
265 QList< QByteArray > responseHeaders (
const QByteArray &key)
const;
268 QList< QByteArray > responseHeaders (
HttpHeader header)
const;
283 bool setResponseHeader (
const QByteArray &key,
const QByteArray &value,
bool append =
false);
286 bool setResponseHeader (
HttpHeader header,
const QByteArray &value,
bool append =
false);
292 bool setResponseHeaders (
const HeaderMap &headers);
302 bool pipeToClient (QIODevice *device, qint64 maxlen = -1);
316 bool pipeFromPostBody (QIODevice *device,
bool takeOwnership =
false);
323 qint64 rangeStart ()
const;
330 qint64 rangeEnd ()
const;
336 qint64 contentLength ()
const;
343 bool setRangeStart (qint64 pos);
350 bool setRangeEnd (qint64 pos);
357 bool setContentLength (qint64 length);
364 virtual bool isSequential ()
const;
370 qint64 postBodyLength ()
const;
375 qint64 postBodyTransferred ();
380 QHostAddress localAddress ()
const;
385 quint16 localPort ()
const;
390 QHostAddress peerAddress ()
const;
395 quint16 peerPort ()
const;
401 int responseCode ()
const;
406 void setResponseCode (
int code);
412 bool isConnectionSecure ()
const;
420 typedef QMap< QByteArray, QNetworkCookie >
Cookies;
435 QNetworkCookie cookie (
const QByteArray &name);
442 bool hasCookie (
const QByteArray &name);
452 void setCookie (
const QByteArray &name,
const QByteArray &value,
453 const QDateTime &expires,
bool secure =
false);
469 void setCookie (
const QByteArray &name,
const QByteArray &value,
470 qint64 maxAge = 0,
bool secure =
false);
479 void setCookie (
const QNetworkCookie &cookie);
489 void removeCookie (
const QByteArray &name);
495 bool keepConnectionOpen ()
const;
507 void setKeepConnectionOpen (
bool keepOpen);
518 void setSlotInfo (
const SlotInfo &info);
527 bool hasReadablePostBody ()
const;
543 bool atEnd ()
const override;
546 qint64 pos ()
const override;
547 qint64 size ()
const override;
548 bool seek (qint64 pos)
override;
549 bool reset ()
override;
554 void disconnected ();
560 void postBodyComplete ();
573 bool killConnection (
int error,
const QString &cause = QString());
581 bool sendResponseHeader ();
593 void close ()
override;
604 void clientDisconnected ();
607 void receivedData ();
610 void pipeToClientReadyRead ();
615 virtual qint64 readData (
char *data, qint64 maxlen);
618 virtual qint64 writeData (
const char *data, qint64 len);
625 bool resolveUrl (
const QUrl &url);
630 bool bufferPostBody ();
639 bool readRangeRequestHeader ();
647 void readRequestCookies ();
649 qint64 parseIntegerHeaderValue (
const QByteArray &value);
650 bool readPostBodyContentLength ();
651 bool send100ContinueIfClientExpectsIt ();
652 bool readAllAvailableHeaderLines ();
653 bool readFirstLine (
const QByteArray &line);
654 bool readHeader (
const QByteArray &line);
655 bool isReceivedHeaderHttp11Compliant ();
656 bool verifyPostRequestCompliance ();
657 bool verifyCompleteHeader ();
658 bool invokeRequestedPath ();
659 bool closeConnectionIfNoLongerNeeded ();
660 bool verifyRequestBodyOrClose ();
661 bool requestHasPostBody ()
const;
662 bool postProcessRequestHeader ();
663 bool contentTypeIsMultipart (
const QByteArray &value)
const;
670 bool sendPipeChunkToClient ();
673 HttpClientPrivate *d_ptr;
679 Q_DECLARE_OPERATORS_FOR_FLAGS(Nuria::HttpClient::HttpVerbs)
680 Q_DECLARE_METATYPE(Nuria::HttpClient::HttpVersion)
681 Q_DECLARE_METATYPE(Nuria::HttpClient::HttpVerbs)
682 Q_DECLARE_METATYPE(Nuria::HttpClient::HttpVerb)
683 Q_DECLARE_METATYPE(Nuria::HttpClient*)
685 #endif // NURIA_HTTPCLIENT_HPP
HttpHeader
Definition: httpclient.hpp:135
QMultiMap< QByteArray, QByteArray > HeaderMap
Definition: httpclient.hpp:172
User-Agent, must be present in a HTTP/1.1 session.
Definition: httpclient.hpp:146
The HttpServer class provides a simple HTTP server. This server is directed at providing interactive ...
Definition: httpserver.hpp:40
Http 1.0.
Definition: httpclient.hpp:104
The HttpClient class represents a connection to a client.
Definition: httpclient.hpp:92
Definition: httpnode.hpp:39
QMap< QByteArray, QNetworkCookie > Cookies
Definition: httpclient.hpp:420
The HttpNode class represents a virtual directory (or a virtual file) HttpServer uses these nodes to ...
Definition: httpnode.hpp:140
Abstract class for readers of the body of HTTP POST requests.
Definition: httppostbodyreader.hpp:41
HttpVerb
Definition: httpclient.hpp:112
HttpVersion
Definition: httpclient.hpp:102
Abstract data transport for HttpClient.
Definition: httptransport.hpp:34