Electroneum
http_request.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common.h"
4 #include "ci_map.h"
5 #include "query_string.h"
6 #include <boost/asio.hpp>
7 
8 namespace crow
9 {
10  template <typename T>
11  inline const std::string& get_header_value(const T& headers, const std::string& key)
12  {
13  if (headers.count(key))
14  {
15  return headers.find(key)->second;
16  }
17  static std::string empty;
18  return empty;
19  }
20 
21  struct DetachHelper;
22 
23  struct request
24  {
26  std::string raw_url;
27  std::string url;
30  std::string body;
31 
33  boost::asio::io_service* io_service{};
34 
37  {
38  }
39 
40  request(HTTPMethod method, std::string raw_url, std::string url, query_string url_params, ci_map headers, std::string body)
41  : method(method), raw_url(std::move(raw_url)), url(std::move(url)), url_params(std::move(url_params)), headers(std::move(headers)), body(std::move(body))
42  {
43  }
44 
45  void add_header(std::string key, std::string value)
46  {
47  headers.emplace(std::move(key), std::move(value));
48  }
49 
50  const std::string& get_header_value(const std::string& key) const
51  {
52  return crow::get_header_value(headers, key);
53  }
54 
55  template<typename CompletionHandler>
56  void post(CompletionHandler handler)
57  {
58  io_service->post(handler);
59  }
60 
61  template<typename CompletionHandler>
62  void dispatch(CompletionHandler handler)
63  {
64  io_service->dispatch(handler);
65  }
66 
67  };
68 }
query_string url_params
Definition: http_request.h:28
const uint32_t T[512]
Definition: groestl_tables.h:34
Definition: http_request.h:23
request()
Definition: http_request.h:35
std::string body
Definition: http_request.h:30
Definition: block_queue.cpp:41
boost::asio::io_service * io_service
Definition: http_request.h:33
ci_map headers
Definition: http_request.h:29
const std::string & get_header_value(const std::string &key) const
Definition: http_request.h:50
std::string url
Definition: http_request.h:27
void post(CompletionHandler handler)
Definition: http_request.h:56
const std::string & get_header_value(const T &headers, const std::string &key)
Definition: http_request.h:11
HTTPMethod method
Definition: http_request.h:25
void * middleware_context
Definition: http_request.h:32
void add_header(std::string key, std::string value)
Definition: http_request.h:45
std::unordered_multimap< std::string, std::string, ci_hash, ci_key_eq > ci_map
Definition: ci_map.h:33
void dispatch(CompletionHandler handler)
Definition: http_request.h:62
Definition: ci_map.h:7
request(HTTPMethod method, std::string raw_url, std::string url, query_string url_params, ci_map headers, std::string body)
Definition: http_request.h:40
std::string raw_url
Definition: http_request.h:26
HTTPMethod
Definition: common.h:11
Definition: query_string.h:239