mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd: Move resource::request related off the stack into client.
This commit is contained in:
parent
e149f38d79
commit
9173c13b89
5 changed files with 35 additions and 38 deletions
|
@ -46,19 +46,19 @@ struct ircd::client
|
|||
|
||||
struct conf *conf {&default_conf};
|
||||
unique_buffer<mutable_buffer> head_buffer;
|
||||
unique_buffer<mutable_buffer> content_buffer;
|
||||
std::shared_ptr<socket> sock;
|
||||
ircd::timer timer;
|
||||
http::request::head head;
|
||||
size_t head_length {0};
|
||||
unique_buffer<mutable_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<void> 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();
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
namespace ircd
|
||||
{
|
||||
struct client;
|
||||
struct resource;
|
||||
}
|
||||
|
||||
|
@ -83,17 +84,23 @@ struct ircd::resource::request
|
|||
{
|
||||
template<class> 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<string_view> parv;
|
||||
|
||||
request(const http::request::head &head,
|
||||
const string_view &content,
|
||||
http::query::string query,
|
||||
const vector_view<string_view> &parv);
|
||||
const string_view &content)
|
||||
:json::object{content}
|
||||
,head{head}
|
||||
,content{content}
|
||||
,query{head.query}
|
||||
{}
|
||||
|
||||
request() = default;
|
||||
};
|
||||
|
||||
template<class tuple>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<string_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<string_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}
|
||||
|
|
Loading…
Reference in a new issue