BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
connection.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <memory>
3 #include <string>
4 #include <vector>
5 
6 namespace fc {
7  namespace ip { class endpoint; }
8  class tcp_socket;
9 
10  namespace http {
11 
12  struct header
13  {
14  header( std::string k, std::string v )
15  :key(std::move(k)),val(std::move(v)){}
16  header(){}
17  std::string key;
18  std::string val;
19  };
20 
21  typedef std::vector<header> headers;
22 
23  struct reply
24  {
25  enum status_code {
26  OK = 200,
28  NoContent = 204,
29  BadRequest = 400,
31  NotFound = 404,
32  Found = 302,
34  };
36  int status;
37  std::vector<header> headers;
38  std::vector<char> body;
39  std::string body_as_string;
40  };
41 
42  struct request
43  {
44  std::string get_header( const std::string& key )const;
45  std::string remote_endpoint;
46  std::string method;
47  std::string domain;
48  std::string path;
49  std::vector<header> headers;
50  std::vector<char> body;
51  };
52 
53  std::vector<header> parse_urlencoded_params( const std::string& f );
54 
59  class connection
60  {
61  public:
62  connection();
63  ~connection();
64  // used for clients
65  void connect_to( const fc::ip::endpoint& ep );
66  http::reply request( const std::string& method, const std::string& url, const std::string& body = std::string(), const headers& = headers());
67 
68  // used for servers
69  fc::tcp_socket& get_socket()const;
70 
72 
73  class impl;
74  private:
75  std::unique_ptr<impl> my;
76  };
77 
78  typedef std::shared_ptr<connection> connection_ptr;
79 
80 } } // fc::http
81 
82 #include <fc/reflect/reflect.hpp>
83 FC_REFLECT( fc::http::header, (key)(val) )
84 FC_REFLECT( fc::http::reply, (status)(headers)(body)(body_as_string) )
fc::http::reply::body
std::vector< char > body
Definition: connection.hpp:38
fc::http::reply::OK
@ OK
Definition: connection.hpp:26
fc::http::reply::Found
@ Found
Definition: connection.hpp:32
fc::http::header::header
header(std::string k, std::string v)
Definition: connection.hpp:14
fc::http::header::key
std::string key
Definition: connection.hpp:17
fc::http::reply::InternalServerError
@ InternalServerError
Definition: connection.hpp:33
fc::http::reply::body_as_string
std::string body_as_string
Definition: connection.hpp:39
fc::http::request
Definition: connection.hpp:42
fc::http::request::path
std::string path
Definition: connection.hpp:48
fc
Definition: api.hpp:15
fc::http::reply::BadRequest
@ BadRequest
Definition: connection.hpp:29
fc::http::reply::reply
reply(status_code c=OK)
Definition: connection.hpp:35
fc::http::reply::headers
std::vector< header > headers
Definition: connection.hpp:37
fc::http::request::headers
std::vector< header > headers
Definition: connection.hpp:49
reflect.hpp
Defines types and macros used to provide reflection.
fc::http::reply::NotAuthorized
@ NotAuthorized
Definition: connection.hpp:30
fc::http::request::get_header
std::string get_header(const std::string &key) const
Definition: http_connection.cpp:174
fc::http::connection::read_request
http::request read_request() const
Definition: http_connection.cpp:135
fc::http::headers
std::vector< header > headers
Definition: connection.hpp:21
fc::asio::tcp::endpoint
boost::asio::ip::tcp::endpoint endpoint
Definition: asio.hpp:239
fc::http::connection::get_socket
fc::tcp_socket & get_socket() const
Definition: http_connection.cpp:131
fc::ip::endpoint
Definition: ip.hpp:65
fc::http::header::val
std::string val
Definition: connection.hpp:18
fc::http::reply::RecordCreated
@ RecordCreated
Definition: connection.hpp:27
fc::http::connection::~connection
~connection()
Definition: http_connection.cpp:82
fc::http::reply::NotFound
@ NotFound
Definition: connection.hpp:31
fc::http::connection_ptr
std::shared_ptr< connection > connection_ptr
Definition: connection.hpp:78
fc::http::request::method
std::string method
Definition: connection.hpp:46
fc::tcp_socket
Definition: tcp_socket.hpp:14
fc::http::connection::connect_to
void connect_to(const fc::ip::endpoint &ep)
Definition: http_connection.cpp:86
fc::http::reply::NoContent
@ NoContent
Definition: connection.hpp:28
fc::http::reply::status
int status
Definition: connection.hpp:36
fc::http::connection
Definition: connection.hpp:59
fc::http::request::body
std::vector< char > body
Definition: connection.hpp:50
fc::http::parse_urlencoded_params
std::vector< header > parse_urlencoded_params(const std::string &f)
Definition: http_connection.cpp:180
std
Definition: zeroed_array.hpp:76
fc::http::request::remote_endpoint
std::string remote_endpoint
Definition: connection.hpp:45
fc::http::header
Definition: connection.hpp:12
fc::http::reply
Definition: connection.hpp:23
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
fc::http::request::domain
std::string domain
Definition: connection.hpp:47
fc::http::reply::status_code
status_code
Definition: connection.hpp:25
fc::url
Definition: url.hpp:22
fc::http::header::header
header()
Definition: connection.hpp:16
fc::http::connection::request
http::reply request(const std::string &method, const std::string &url, const std::string &body=std::string(), const headers &=headers())
Definition: http_connection.cpp:91
fc::http::connection::connection
connection()
Definition: http_connection.cpp:80
fc::http::connection::impl
Definition: http_connection.cpp:14