9 #include "httpconnection.h"
44 const std::string &http_hostname = std::string(),
46 struct addrinfo *local_addr =
nullptr);
59 buffer_response =
false;
65 return response_http_status;
70 auto p = http_response_headers.find(
"content-type");
71 if (p == http_response_headers.end())
77 const std::string &rawHttpHeader()
const {
78 return response_header;
81 const std::multimap<std::string, std::string> &responseHeaders()
const {
82 return http_response_headers;
85 size_t remainingContentLength()
const {
86 return bytes_left_to_read;
89 std::string contents()
const {
94 void get(
const std::string &url);
99 void post(
const std::string &url,
size_t len);
110 void post(
const std::string &url,
const std::string &data);
113 void ws_get(
const std::string &url);
118 current_request =
"pass";
121 return current_request.empty() ||
122 current_request ==
"pass";
125 static std::string urlencode(
const std::string &val);
126 static void addUrlPars(std::string &url,
127 const std::map<std::string, std::string> &pars);
132 std::string real_hostname;
136 std::string proto_hostname;
137 std::string current_request, current_uri;
140 std::string websocket_rkey;
143 std::string response_header;
145 const std::string::size_type max_header_length = 20000;
147 bool response_header_complete =
false;
149 bool response_is_chunked;
151 bool buffer_response =
true;
152 size_t bytes_left_to_read = 0;
153 size_t bytes_left_to_post = 0;
154 unsigned int response_http_status = 0;
155 std::string chunked_info;
157 bool parseResponseHeaders();
158 std::multimap<std::string, std::string> http_response_headers;
159 bool parseChunkedEncodingLength(
char *&buf,
size_t &len);
HTTP/1.1 client protocol.
Definition: httpclientconnection.h:39
PollState writeData() final
For HTTP POST.
Definition: httpclientconnection.cpp:272
void doStreamResponse()
Definition: httpclientconnection.h:58
void post(const std::string &url, size_t len)
Definition: httpclientconnection.cpp:376
unsigned int httpStatus() const
Definition: httpclientconnection.h:64
void get(const std::string &url)
May be called in the newRequest callback:
Definition: httpclientconnection.cpp:317
void ws_get(const std::string &url)
May be called in the newRequest callback to open a websocket.
Definition: httpclientconnection.cpp:328
std::string contentType() const
Return value of first Content-Type header, empty string on failure.
Definition: httpclientconnection.h:69
PollState connected() final
Will be called when the connection is established.
Definition: httpclientconnection.cpp:31
PollState readData(char *buf, size_t len) final
Callback, called when data has arrived; len > 0.
Definition: httpclientconnection.cpp:102
std::string cacheLabel() override
Return the socket's cache group, or an empty string.
Definition: httpclientconnection.cpp:388
void setOwner(Task *new_owner) override
Set the given task as owner of the socket.
Definition: httpclientconnection.cpp:392
void pass()
Definition: httpclientconnection.h:117
API for HTTP clients.
Definition: httpclienttask.h:11
Definition: httpconnection.h:11
std::string label() const
Return the object's log label.
Definition: logger.h:251
std::string hostname() const
Return name of the host to which the socket is supposed to connect.
Definition: socket.h:32
uint16_t port() const
Return port number to which the socket is supposed to connect.
Definition: socket.h:37
The purpose of a task is to manage socket connections, and/or to execute timers.
Definition: task.h:39
PollState
Definition: pollstate.h:11