Fledge
An open source edge computing platform for industrial users
simple_https.h
1 #ifndef _SIMPLE_HTTPS_H
2 #define _SIMPLE_HTTPS_H
3 /*
4  * Fledge HTTP Sender wrapper.
5  *
6  * Copyright (c) 2018 Diamnomic Systems
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Massimiliano Pinto, Mark Riddoch, Stefano Simonelli
11  */
12 
13 #include <string>
14 #include <vector>
15 #include <http_sender.h>
16 #include <client_https.hpp>
17 #include <fstream>
18 
19 using HttpsClient = SimpleWeb::Client<SimpleWeb::HTTPS>;
20 
21 class SimpleHttps: public HttpSender
22 {
23  public:
28  SimpleHttps(const std::string& host_port,
29  unsigned int connect_timeout = 0,
30  unsigned int request_timeout = 0,
31  unsigned int retry_sleep_Time = 1,
32  unsigned int max_retry = 4);
33 
34  // Destructor
35  ~SimpleHttps();
36 
40  void setProxy(const std::string& proxy);
41 
45  int sendRequest(
46  const std::string& method = std::string(HTTP_SENDER_DEFAULT_METHOD),
47  const std::string& path = std::string(HTTP_SENDER_DEFAULT_PATH),
48  const std::vector<std::pair<std::string, std::string>>& headers = {},
49  const std::string& payload = std::string()
50  );
51 
52  void setAuthMethod (std::string& authMethod) {m_authMethod = authMethod; }
53  void setAuthBasicCredentials(std::string& authBasicCredentials) {m_authBasicCredentials = authBasicCredentials; }
54  void setMaxRetries (unsigned int retries) {m_max_retry = retries; };
55 
56  // OCS configurations
57  void setOCSNamespace (std::string& OCSNamespace) {m_OCSNamespace = OCSNamespace; }
58  void setOCSTenantId (std::string& OCSTenantId) {m_OCSTenantId = OCSTenantId; }
59  void setOCSClientId (std::string& OCSClientId) {m_OCSClientId = OCSClientId; }
60  void setOCSClientSecret (std::string& OCSClientSecret) {m_OCSClientSecret = OCSClientSecret; }
61  void setOCSToken (std::string& OCSToken) {m_OCSToken = OCSToken; }
62 
63  std::string getHTTPResponse() { return m_HTTPResponse; };
64  std::string getHostPort() { return m_host_port; };
65  unsigned int getMaxRetries() { return m_max_retry; };
66 
67  private:
68  // Make private the copy constructor and operator=
69  SimpleHttps(const SimpleHttps&);
70  SimpleHttps& operator=(SimpleHttps const &);
71  void setTrace();
72  void resetTrace();
73  private:
74  std::string m_host_port;
75  HttpsClient *m_sender;
76  std::string m_HTTPResponse;
77  unsigned int m_retry_sleep_time; // Seconds between each retry
78  unsigned int m_max_retry; // Max number of retries in the communication
79 
80  std::string m_authMethod; // Authentication method to be used
81  std::string m_authBasicCredentials; // Credentials is the base64 encoding of id and password joined by a single colon (:)
82 
83  // OCS configurations
84  std::string m_OCSNamespace;
85  std::string m_OCSTenantId;
86  std::string m_OCSClientId;
87  std::string m_OCSClientSecret;
88  std::string m_OCSToken;
89  bool m_log;
90  std::ofstream m_ofs;
91 
92 };
93 
94 #endif
SimpleHttps::setProxy
void setProxy(const std::string &proxy)
Set the host and port of the proxy server.
Definition: simple_https.cpp:101
SimpleHttps::~SimpleHttps
~SimpleHttps()
Destructor.
Definition: simple_https.cpp:61
SimpleHttps::sendRequest
int sendRequest(const std::string &method=std::string(HTTP_SENDER_DEFAULT_METHOD), const std::string &path=std::string(HTTP_SENDER_DEFAULT_PATH), const std::vector< std::pair< std::string, std::string >> &headers={}, const std::string &payload=std::string())
HTTP(S) request: pass method and path, HTTP headers and POST/PUT payload.
Definition: simple_https.cpp:118
SimpleHttps::SimpleHttps
SimpleHttps(const std::string &host_port, unsigned int connect_timeout=0, unsigned int request_timeout=0, unsigned int retry_sleep_Time=1, unsigned int max_retry=4)
Constructor: pass host:port, connect & request timeouts.
SimpleHttps
Definition: simple_https.h:21
HttpSender
Definition: http_sender.h:20