nx_server_plugin_sdk 1.0 Server Plugin SDK

sync_http_client.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <QtNetwork/QAuthenticator>
6 #include <QtNetwork/QNetworkAccessManager>
7 #include <QtNetwork/QNetworkReply>
8 #include <QtNetwork/QNetworkRequest>
9
10 class SyncHttpClientDelegate;
11
13
18 class SyncHttpClient
19 {
20 public:
21 static const int HTTP_OK = 200;
22 static const int HTTP_BAD_REQUEST = 400;
23 static const int HTTP_NOT_AUTHORIZED = 401;
24
31 SyncHttpClient(
32 QNetworkAccessManager* networkAccessManager,
33 const QUrl& defaultUrl = QUrl(),
34 int defaultPort = 0,
35 const QAuthenticator& defaultCredentials = QAuthenticator() );
36 SyncHttpClient(
37 QNetworkAccessManager* networkAccessManager,
38 const QString& defaultUrlStr,
39 int defaultPort = 0,
40 const QAuthenticator& defaultCredentials = QAuthenticator() );
41 ~SyncHttpClient();
42
44
49 QNetworkReply::NetworkError get( const QNetworkRequest& request );
51 QNetworkReply::NetworkError get( const QUrl& requestUrl );
53 QNetworkReply::NetworkError get( const QString& requestUrl );
55 QByteArray readWholeMessageBody();
57 int statusCode() const;
58
59 private:
60 QNetworkAccessManager* m_networkAccessManager;
61 QUrl m_defaultUrl;
62 SyncHttpClientDelegate* m_delegate;
63
64 void init(
65 int defaultPort,
66 const QAuthenticator& defaultCredentials );
67 };
SyncHttpClient::SyncHttpClient
SyncHttpClient(QNetworkAccessManager *networkAccessManager, const QUrl &defaultUrl=QUrl(), int defaultPort=0, const QAuthenticator &defaultCredentials=QAuthenticator())
Definition: sync_http_client.cpp:11
SyncHttpClient::statusCode
int statusCode() const
Holds http status code of prev request. Undefined, if get returned code different from QNetworkReply:...
Definition: sync_http_client.cpp:84
SyncHttpClientDelegate
Helper class, used by SyncHttpClient.
Definition: sync_http_client_delegate.h:15
SyncHttpClient::readWholeMessageBody
QByteArray readWholeMessageBody()
Reads whole message body. May block.
Definition: sync_http_client.cpp:79
SyncHttpClient
Synchronous wrapper on top of QNetworkAccessManager.
Definition: sync_http_client.h:18