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 
55  // OCS configurations
56  void setOCSNamespace (std::string& OCSNamespace) {m_OCSNamespace = OCSNamespace; }
57  void setOCSTenantId (std::string& OCSTenantId) {m_OCSTenantId = OCSTenantId; }
58  void setOCSClientId (std::string& OCSClientId) {m_OCSClientId = OCSClientId; }
59  void setOCSClientSecret (std::string& OCSClientSecret) {m_OCSClientSecret = OCSClientSecret; }
60  void setOCSToken (std::string& OCSToken) {m_OCSToken = OCSToken; }
61 
62  std::string getHTTPResponse() { return m_HTTPResponse; };
63  std::string getHostPort() { return m_host_port; };
64 
65  private:
66  // Make private the copy constructor and operator=
67  SimpleHttps(const SimpleHttps&);
68  SimpleHttps& operator=(SimpleHttps const &);
69  void setTrace();
70  void resetTrace();
71  private:
72  std::string m_host_port;
73  HttpsClient *m_sender;
74  std::string m_HTTPResponse;
75  unsigned int m_retry_sleep_time; // Seconds between each retry
76  unsigned int m_max_retry; // Max number of retries in the communication
77 
78  std::string m_authMethod; // Authentication method to be used
79  std::string m_authBasicCredentials; // Credentials is the base64 encoding of id and password joined by a single colon (:)
80 
81  // OCS configurations
82  std::string m_OCSNamespace;
83  std::string m_OCSTenantId;
84  std::string m_OCSClientId;
85  std::string m_OCSClientSecret;
86  std::string m_OCSToken;
87  bool m_log;
88  std::ofstream m_ofs;
89 
90 };
91 
92 #endif
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.
void setProxy(const std::string &proxy)
Set the host and port of the proxy server.
Definition: simple_https.cpp:101
~SimpleHttps()
Destructor.
Definition: simple_https.cpp:61
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
Definition: http_sender.h:20
Definition: simple_https.h:21