CoreSDK  v1.0.0.b1304
r5net.h
1 /*
2  * Copyright (c) 2022 Infrared5, Inc.
3  * License information: https://account.red5.net/assets/LICENSE.txt
4  *
5  */
6 
7 #pragma once
8 
9 #include "r5common.h"
10 
11 #include <list>
12 #include <string>
13 
14 namespace r5::net {
15 
21 {
22  std::string host;
23  std::string port;
24  std::string path;
25 };
30 enum class NetError {
31  Ok,
32  ResolveFailed,
33  ConnectionFailed,
34  HandshakeFailed,
35  RequestFailed,
36  ResponseFailed,
37  UrlParseFailed,
38  ResponseParsingError,
39  ReadError,
40  WriteError,
41  ProtocolNotSupported,
42  GeneralNetError
43 };
48 enum class Protocol {
49  Http,
50  Https
51 };
56 enum class ContentType {
57  Unknown,
58  Json
59 };
64 struct HttpHeader
65 {
66  std::string key;
67  std::string value;
68 };
74 {
75  std::list<HttpHeader> headers;
76  ContentType contentType = ContentType::Unknown;
77  std::string body;
78 };
84 {
85  int statusCode = -1;
86  ContentType contentType;
87  std::string body;
88 };
93 class R5_SDK_CORE_EXPORT HttpClient
94 {
95 public:
96  HttpClient();
97 
110  static NetError Get(Protocol protocol, const std::string &host, int port, const std::string &path, r5::common::ILoggerPtr logger = nullptr,
111  HttpRequest *req = nullptr, HttpResponse *resp = nullptr);
124  static NetError Post(Protocol protocol, const std::string &host, int port, const std::string &path, r5::common::ILoggerPtr logger = nullptr,
125  HttpRequest *req = nullptr, HttpResponse *resp = nullptr);
126 
139  static NetError Put(Protocol protocol, const std::string &host, int port, const std::string &path, r5::common::ILoggerPtr logger = nullptr,
140  HttpRequest *req = nullptr, HttpResponse *resp = nullptr);
153  static NetError Delete(Protocol protocol, const std::string &host, int port, const std::string &path, r5::common::ILoggerPtr logger = nullptr,
154  HttpRequest *req = nullptr, HttpResponse *resp = nullptr);
155 };
156 }
Helper class for sending different HTTP/HTTPS requests.
Definition: r5net.h:93
HTTP request description.
Definition: r5net.h:73
ContentType contentType
Content type of HTTP response body.
Definition: r5net.h:86
std::string key
Key of header record.
Definition: r5net.h:66
std::string body
Content of HTTP response.
Definition: r5net.h:87
std::string port
Connection port.
Definition: r5net.h:23
std::list< HttpHeader > headers
Header of HTTP request.
Definition: r5net.h:75
HTTP response description.
Definition: r5net.h:83
Structure for configuring websocket connection.
Definition: r5net.h:20
std::string body
Content of HTTP request.
Definition: r5net.h:77
std::string host
Server ip or host name.
Definition: r5net.h:22
HTTP header record structure.
Definition: r5net.h:64
Definition: r5net.h:14
std::string value
Value of header record.
Definition: r5net.h:67
std::string path
Path to resource on server.
Definition: r5net.h:24