12 #include "httpclienttask.h"
15 const std::string &url;
16 unsigned int http_status;
17 const std::string &response;
23 unsigned int min_conn = 0,
unsigned int max_conn = 10,
24 double tick_duration = 0.5) :
26 min_connections(std::min(min_conn, max_conn)),
27 max_connections(max_conn),
28 no_connections(min_connections),
29 active_connections(0),
30 tick(tick_duration > 0.0 ? tick_duration : 0.5) {
36 void getJob(
Task *task,
const std::string &event_name,
37 const std::string &url) {
38 postJob(task, event_name, url,
"");
41 void postJob(
Task *task,
const std::string &event_name,
42 const std::string &url,
const std::string &data);
46 unsigned int httpStatus()
const {
47 return last_completed ? last_completed->
httpStatus() : 0;
52 std::string contentType()
const {
53 return last_completed ? last_completed->
contentType() :
"";
58 const std::string contents()
const {
59 return last_completed ? last_completed->contents() :
"";
64 const std::string ¤tUrl()
const {
65 static std::string dummy;
66 return current_job ? current_job->url : dummy;
72 redo_job = current_job;
77 void redoJob(
const std::string &url) {
79 current_job->url = url;
80 current_job->data.clear();
85 void redoJob(
const std::string &url,
const std::string &data) {
87 current_job->url = url;
88 current_job->data = data;
97 virtual void connectionLost() {
98 dbg_log() <<
"connectionLost() not implemented";
104 std::string event_name, url, data;
107 double start()
final;
109 double timerEvent()
final;
112 void cancelRequestsByTask(
Task *task);
118 void checkConnectionCount();
121 unsigned int min_connections, max_connections;
122 unsigned int no_connections, active_connections;
133 std::deque<HREJob *> incoming_jobs;
135 std::set<SocketConnection *> idle_connections;
136 std::map<HttpClientConnection *, HREJob *> active_jobs;
HTTP/1.1 client protocol.
Definition: httpclientconnection.h:39
unsigned int httpStatus() const
Definition: httpclientconnection.h:64
std::string contentType() const
Return value of first Content-Type header, empty string on failure.
Definition: httpclientconnection.h:69
API for HTTP clients.
Definition: httpclienttask.h:11
The host name and port number of a HTTP host.
Definition: httphost.h:17
Definition: httprequestengine.h:20
void taskFinished(Task *t) override
Definition: httprequestengine.cpp:128
std::ostream & dbg_log() const
Write a line of debug log.
Definition: logger.h:345
This class implements low-level socket connection operations. Inherit from it to implement protocols ...
Definition: socketconnection.h:47
The purpose of a task is to manage socket connections, and/or to execute timers.
Definition: task.h:39
Definition: httprequestengine.h:14