diff --git a/include/ircd/client.h b/include/ircd/client.h index edb9cc678..c34a2a536 100644 --- a/include/ircd/client.h +++ b/include/ircd/client.h @@ -46,19 +46,19 @@ struct ircd::client struct conf *conf {&default_conf}; unique_buffer head_buffer; + unique_buffer content_buffer; std::shared_ptr sock; ircd::timer timer; - http::request::head head; size_t head_length {0}; - unique_buffer content_buffer; size_t content_consumed {0}; + resource::request request; bool longpoll {false}; void close(const net::close_opts &, net::close_callback); ctx::future close(const net::close_opts & = {}); - void discard_unconsumed(); - bool resource_request(); + void discard_unconsumed(const http::request::head &); + bool resource_request(const http::request::head &); bool handle_request(parse::capstan &pc); bool main() noexcept; void async(); diff --git a/include/ircd/resource.h b/include/ircd/resource.h index ba72937af..e4a98bf27 100644 --- a/include/ircd/resource.h +++ b/include/ircd/resource.h @@ -13,6 +13,7 @@ namespace ircd { + struct client; struct resource; } @@ -83,17 +84,23 @@ struct ircd::resource::request { template struct object; - const http::request::head &head; + http::request::head head; string_view content; http::query::string query; string_view user_id; //m::user::id::buf user_id; //TODO: bleeding string_view access_token; + string_view param[8]; vector_view parv; request(const http::request::head &head, - const string_view &content, - http::query::string query, - const vector_view &parv); + const string_view &content) + :json::object{content} + ,head{head} + ,content{content} + ,query{head.query} + {} + + request() = default; }; template diff --git a/include/ircd/stdinc.h b/include/ircd/stdinc.h index cf4493796..11dfcbf73 100644 --- a/include/ircd/stdinc.h +++ b/include/ircd/stdinc.h @@ -227,5 +227,5 @@ namespace ircd #include "rfc1035.h" #include "net/net.h" #include "server/server.h" -#include "client.h" #include "resource.h" +#include "client.h" diff --git a/ircd/client.cc b/ircd/client.cc index d45e4495f..386e7f7e7 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -603,7 +603,7 @@ try // This is the first read off the wire. The headers are entirely read and // the tape is advanced. timer = ircd::timer{}; - head = http::request::head{pc}; + const http::request::head head{pc}; head_length = pc.parsed - data(head_buffer); content_consumed = std::min(pc.unparsed(), head.content_length); pc.parsed += content_consumed; @@ -620,7 +620,7 @@ try bool ret { - resource_request() + resource_request(head) }; if(ret && iequals(head.connection, "close"_sv)) @@ -657,7 +657,7 @@ catch(const ircd::error &e) } bool -ircd::client::resource_request() +ircd::client::resource_request(const http::request::head &head) try { const string_view content_partial @@ -671,7 +671,7 @@ try }; resource(*this, head, content_partial); - discard_unconsumed(); + discard_unconsumed(head); return true; } catch(const http::error &e) @@ -694,17 +694,20 @@ catch(const http::error &e) // These codes are "recoverable" and allow the next HTTP request in // a pipeline to take place. default: - discard_unconsumed(); + discard_unconsumed(head); return true; } } void -ircd::client::discard_unconsumed() +ircd::client::discard_unconsumed(const http::request::head &head) { if(unlikely(!sock)) return; + if(longpoll) + return; + const size_t unconsumed { head.content_length - content_consumed diff --git a/ircd/resource.cc b/ircd/resource.cc index 229c1675a..00de6745b 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -284,29 +284,28 @@ ircd::resource::operator()(client &client, }; } + client.request = resource::request + { + head, content + }; + const auto pathparm { lstrip(head.path, this->path) }; - string_view param[8]; - const vector_view parv + client.request.parv = { - param, tokens(pathparm, '/', param) - }; - - resource::request resource_request - { - head, content, head.query, parv + client.request.param, tokens(pathparm, '/', client.request.param) }; if(method.opts.flags & method.REQUIRES_AUTH) - authenticate(client, method, resource_request); + authenticate(client, method, client.request); if(method.opts.flags & method.VERIFY_ORIGIN) - verify_origin(client, method, resource_request); + verify_origin(client, method, client.request); - handle_request(client, method, resource_request); + handle_request(client, method, client.request); } void @@ -439,18 +438,6 @@ catch(const std::bad_function_call &e) }; } -ircd::resource::request::request(const http::request::head &head, - const string_view &content, - http::query::string query, - const vector_view &parv) -:json::object{content} -,head{head} -,content{content} -,query{std::move(query)} -,parv{parv} -{ -} - ircd::resource::response::response(client &client, const http::code &code) :response{client, json::object{"{}"}, code}