libtasks Documentation  1.6
http_request.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #ifndef _HTTP_REQUEST_H_
9 #define _HTTP_REQUEST_H_
10 
11 #include <tasks/net/http_base.h>
12 
13 namespace tasks {
14 namespace net {
15 
17 class http_request : public http_base {
18  public:
24  http_request(std::string host, std::string url = "", int port = 80) : m_host(host), m_url(url), m_port(port) {
25  m_headers["Host"] = m_host;
27  }
28 
30  inline void set_host(std::string host) { m_host = host; }
31 
33  inline void set_url(std::string url) { m_url = url; }
34 
36  inline void set_port(int port) { m_port = port; }
37 
39  inline const std::string& host() const { return m_host; }
40 
42  inline const std::string& url() const { return m_url; }
43 
45  inline int port() const { return m_port; }
46 
48  void prepare_data_buffer();
49 
51  void clear() {
54  m_headers["Host"] = m_host;
55  }
56 
57  private:
58  std::string m_host;
59  std::string m_url;
60  int m_port;
61 
62  void init_default_headers();
63 };
64 
65 } // net
66 } // tasks
67 
68 #endif // _HTTP_REQUEST_H_
http_request(std::string host, std::string url="", int port=80)
Definition: http_request.h:24
void set_url(std::string url)
Set the URL.
Definition: http_request.h:33
const std::string & url() const
Definition: http_request.h:42
The HTTP request implementation.
Definition: http_request.h:17
virtual void clear()
Reset the http object.
Definition: http_base.h:119
std::unordered_map< std::string, std::string > m_headers
Definition: http_base.h:133
void clear()
Reset the http object.
Definition: http_request.h:51
void prepare_data_buffer()
Prepare a HTTP request/response to be sent.
const std::string & host() const
Definition: http_request.h:39
void set_port(int port)
Set the port.
Definition: http_request.h:36
void set_host(std::string host)
Set the host.
Definition: http_request.h:30