This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
http.h
60 lines (47 loc) · 1.41 KB
/
http.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*!
* janus-client SDK
*
* http.h
* An HTTP client
* This class defines an HTTP client based on libcurl
*
* Copyright 2019 Pasquale Boemio <[email protected]>
*/
#pragma once
#include <memory>
#include <string>
namespace Janus {
class HttpResponse {
public:
HttpResponse(int status, const std::string& body);
int status();
std::string body();
private:
int _status;
std::string _body;
};
class Http {
public:
virtual std::shared_ptr<HttpResponse> get(const std::string& path) = 0;
virtual std::shared_ptr<HttpResponse> post(const std::string& path, const std::string& body="") = 0;
};
class HttpImpl : public Http {
public:
HttpImpl(const std::string& baseUrl);
~HttpImpl();
std::shared_ptr<HttpResponse> get(const std::string& path);
std::shared_ptr<HttpResponse> post(const std::string& path, const std::string& body="");
private:
std::shared_ptr<HttpResponse> _request(const std::string& path, const std::string& method, const std::string& body="");
static size_t _writeFunction(void* ptr, size_t size, size_t nmemb, std::string* data);
std::string _baseUrl;
};
class HttpFactory {
public:
virtual std::shared_ptr<Http> create(const std::string& baseUrl) = 0;
};
class HttpFactoryImpl : public HttpFactory {
public:
std::shared_ptr<Http> create(const std::string& baseUrl);
};
}