libtasks Documentation  1.6
http_response.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_RESPONSE_H_
9 #define _HTTP_RESPONSE_H_
10 
11 #define READ_BUFFER_SIZE_BLOCK 4096
12 
13 #include <tasks/net/http_base.h>
14 
15 namespace tasks {
16 namespace net {
17 
19 class http_response : public http_base {
20  public:
22 
23  inline void set_status(std::string status) {
24  m_status = status;
25  m_status_code = std::atoi(status.c_str());
26  }
27 
29  inline const std::string& status() const { return m_status; }
30 
32  inline int status_code() const { return m_status_code; }
33 
35  void prepare_data_buffer();
36 
38  void read_data(net::socket& sock);
39 
41  void clear() {
43  m_status = "";
44  m_line_number = 0;
46  m_content_start = 0;
48  m_chunked_enc = false;
49  }
50 
51  private:
52  std::string m_status;
54  int m_line_number = 0;
55  std::size_t m_last_line_start = 0;
56  std::size_t m_content_start = 0;
58  bool m_chunked_enc = false;
59 
60  void parse_data();
61  void parse_line();
62  void parse_status();
63  void parse_header();
64 };
65 
66 } // net
67 } // tasks
68 
69 #endif // _HTTP_RESPONSE_H_
The HTTP response implementation.
Definition: http_response.h:19
The socket class.
Definition: socket.h:35
void set_status(std::string status)
Definition: http_response.h:23
void clear()
Reset the http object.
Definition: http_response.h:41
const std::string & status() const
Definition: http_response.h:29
virtual void clear()
Reset the http object.
Definition: http_base.h:119
void read_data(net::socket &sock)
Read an HTTP response from a socket.
void prepare_data_buffer()
Prepare a HTTP request/response to be sent.