Chatterino
NetworkCommon.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 #include <vector>
5 
6 #include <QString>
7 
8 class QNetworkReply;
9 
10 namespace chatterino {
11 
12 class Outcome;
13 class NetworkResult;
14 
15 using NetworkSuccessCallback = std::function<Outcome(NetworkResult)>;
16 using NetworkErrorCallback = std::function<void(NetworkResult)>;
17 using NetworkReplyCreatedCallback = std::function<void(QNetworkReply *)>;
18 using NetworkFinallyCallback = std::function<void()>;
19 
20 enum class NetworkRequestType {
21  Get,
22  Post,
23  Put,
24  Delete,
25  Patch,
26 };
27 const static std::vector<QString> networkRequestTypes{
28  "GET", //
29  "POST", //
30  "PUT", //
31  "DELETE", //
32  "PATCH", //
33 };
34 
35 // parseHeaderList takes a list of headers in string form,
36 // where each header pair is separated by semicolons (;) and the header name and value is divided by a colon (:)
37 //
38 // We return a vector of pairs, where the first value is the header name and the second value is the header value
39 //
40 // e.g. "Authorization:secretkey;NextHeader:boo" will return [{"Authorization", "secretkey"}, {"NextHeader", "boo"}]
41 std::vector<std::pair<QByteArray, QByteArray>> parseHeaderList(
42  const QString &headerListString);
43 
44 } // namespace chatterino
Definition: Application.cpp:48
std::function< void(NetworkResult)> NetworkErrorCallback
Definition: NetworkCommon.hpp:16
NetworkRequestType
Definition: NetworkCommon.hpp:20
std::function< Outcome(NetworkResult)> NetworkSuccessCallback
Definition: NetworkCommon.hpp:15
std::vector< std::pair< QByteArray, QByteArray > > parseHeaderList(const QString &headerListString)
Definition: NetworkCommon.cpp:7
std::function< void()> NetworkFinallyCallback
Definition: NetworkCommon.hpp:18
std::function< void(QNetworkReply *)> NetworkReplyCreatedCallback
Definition: NetworkCommon.hpp:17