alaCarte Maps
Renderer for OpenStreetMap tiles
http_request.hpp
Go to the documentation of this file.
1 
21 #pragma once
22 #ifndef HTTP_REQUEST_HPP
23 #define HTTP_REQUEST_HPP
24 
25 #include "settings.hpp"
27 #include <array>
28 
29 class HttpServer;
30 class Tile;
31 class RequestManager;
32 
33 class HttpRequest : public boost::enable_shared_from_this<HttpRequest>, private boost::noncopyable
34 {
35  friend class HttpRequestParser;
36 public:
37 
38  struct Header {
41  };
42 
43  struct RequestData {
48  std::vector<Header> headers;
49  };
50 
51  class Reply
52  {
53  public:
54  enum StatusType {
55  ok = 200,
56  created = 201,
57  accepted = 202,
58  no_content = 204,
62  not_modified = 304,
63  bad_request = 400,
64  unauthorized = 401,
65  forbidden = 403,
66  not_found = 404,
69  bad_gateway = 502,
71  };
75  std::vector<Header> headers;
79  shared_ptr<Tile> tile;
83  std::vector<boost::asio::const_buffer> toBuffers();
84  };
85 
86 public:
87  explicit HttpRequest ( boost::asio::io_service &ioService, const shared_ptr<HttpServer>& server, const shared_ptr<RequestManager> &manager );
88 
89  TESTABLE const string& getURL() const;
90 
91  TESTABLE void answer ( const shared_ptr<Tile>& tile, Reply::StatusType status = Reply::ok );
92  TESTABLE void answer ( Reply::StatusType status );
94  void startCollectingData();
95 
97  void close();
98 
99  boost::asio::ip::tcp::socket &getSocket();
100 private:
102  void handleRead ( const boost::system::error_code &e, std::size_t bytes_transferred );
103 
105  void handleWrite ( const boost::system::error_code &e );
106 
107  void answer();
108  bool checkifAnswered();
109  void readSome();
110 
111 protected:
112  bool answered;
116 private:
117 
119  boost::asio::ip::tcp::socket socket;
121  std::array<char, 8192> buffer;
124 
125  weak_ptr<RequestManager> manager;
126  weak_ptr<HttpServer> server;
127 };
128 
129 
130 #endif
weak_ptr< HttpServer > server
Parser for incoming requests.
const std::string ok
Reply reply
The reply to be sent back to the client.
const std::string forbidden
void handleRead(const boost::system::error_code &e, std::size_t bytes_transferred)
Handle completion of a read operation.
void readSome()
const std::string created
HttpRequest(boost::asio::io_service &ioService, const shared_ptr< HttpServer > &server, const shared_ptr< RequestManager > &manager)
This file is part of alaCarte.
Definition: tile.hpp:30
std::array< char, 8192 > buffer
Buffer for incoming data.
const std::string accepted
std::vector< Header > headers
The headers to be included in the Reply.
RequestData data
std::string string
Definition: settings.hpp:110
TESTABLE const string & getURL() const
std::vector< Header > headers
boost::asio::ip::tcp::socket socket
Socket for the connection.
const std::string not_found
bool checkifAnswered()
void handleWrite(const boost::system::error_code &e)
Handle completion of a write operation.
HttpRequestParser parser
The parser for the incoming request.
A HttpServer waits for connections and creates HttpRequests.
Definition: http_server.hpp:37
const std::string bad_gateway
std::string content
The content to be sent in the Reply.
const std::string not_implemented
const std::string not_modified
const std::string bad_request
void startCollectingData()
Start the first asynchronous operation for the connection.
void close()
Stop all asynchronous operations associated with the connection.
StatusType status
The Status of the Reply.
#define TESTABLE
Definition: settings.hpp:85
const std::string unauthorized
weak_ptr< RequestManager > manager
const std::string internal_server_error
boost::asio::ip::tcp::socket & getSocket()
shared_ptr< Tile > tile
The Tile to be sent in the Reply.
const std::string moved_temporarily
const std::string multiple_choices
const std::string no_content
const std::string moved_permanently
const std::string service_unavailable