@@ -34,8 +34,7 @@ using namespace network::http;
3434using namespace std ::placeholders;
3535using namespace boost ::json;
3636
37- using json_t = json_body::value_type;
38-
37+ BC_PUSH_WARNING (NO_THROW_IN_NOEXCEPT)
3938BC_PUSH_WARNING (SMART_PTR_NOT_NEEDED)
4039BC_PUSH_WARNING (NO_VALUE_OR_CONST_REF_SHARED_PTR)
4140
@@ -74,6 +73,32 @@ void protocol_bitcoind::start() NOEXCEPT
7473// Dispatch.
7574// ----------------------------------------------------------------------------
7675
76+ void protocol_bitcoind::handle_receive_options (const code& ec,
77+ const network::http::method::options::cptr& options) NOEXCEPT
78+ {
79+ BC_ASSERT (stranded ());
80+
81+ if (stopped (ec))
82+ return ;
83+
84+ // Enforce http host header (if any hosts are configured).
85+ if (!is_allowed_host (*options, options->version ()))
86+ {
87+ send_bad_host (*options);
88+ return ;
89+ }
90+
91+ // Enforce http origin policy (if any origins are configured).
92+ if (!is_allowed_origin (*options, options->version ()))
93+ {
94+ send_forbidden (*options);
95+ return ;
96+ }
97+
98+ send_ok (*options);
99+ }
100+
101+ // TODO: also handle_receive_get and dispatch based on URL parse.
77102void protocol_bitcoind::handle_receive_post (const code& ec,
78103 const network::http::method::post ::cptr& post ) NOEXCEPT
79104{
@@ -82,6 +107,21 @@ void protocol_bitcoind::handle_receive_post(const code& ec,
82107 if (stopped (ec))
83108 return ;
84109
110+ // Enforce http host header (if any hosts are configured).
111+ if (!is_allowed_host (*post , post ->version ()))
112+ {
113+ send_bad_host (*post );
114+ return ;
115+ }
116+
117+ // Enforce http origin policy (if any origins are configured).
118+ if (!is_allowed_origin (*post , post ->version ()))
119+ {
120+ send_forbidden (*post );
121+ return ;
122+ }
123+
124+ using json_t = json_body::value_type;
85125 const auto & body = post ->body ();
86126 if (!body.contains <json_t >())
87127 {
@@ -228,6 +268,24 @@ bool protocol_bitcoind::handle_verify_tx_out_set(const code& ec,
228268 return !ec;
229269}
230270
271+ // private
272+ // ----------------------------------------------------------------------------
273+
274+ // TODO: post-process response for json-rpc version.
275+ void protocol_bitcoind::send_json (boost::json::value&& model, size_t size_hint,
276+ const request& request) NOEXCEPT
277+ {
278+ BC_ASSERT (stranded ());
279+ constexpr auto json = media_type::application_json;
280+ response response{ status::ok, request.version () };
281+ add_common_headers (response, request);
282+ response.set (field::content_type, from_media_type (json));
283+ response.body () = { std::move (model), size_hint };
284+ response.prepare_payload ();
285+ SEND (std::move (response), handle_complete, _1, error::success);
286+ }
287+
288+ BC_POP_WARNING ()
231289BC_POP_WARNING ()
232290BC_POP_WARNING ()
233291
0 commit comments