0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::http: Add string views to make the raw head data available.

This commit is contained in:
Jason Volk 2019-01-12 11:52:56 -08:00
parent 3a3dfe40d1
commit b42ded1fc7
2 changed files with 38 additions and 0 deletions

View file

@ -88,6 +88,8 @@ struct ircd::http::line::request
string_view fragment;
string_view version;
operator string_view() const; // full view of line
request(const line &);
request() = default;
};
@ -226,6 +228,9 @@ struct ircd::http::request::head
string_view uri; // full view of (path, query, fragmet)
string_view headers; // full view of all headers
// full view of all head (request line and headers)
operator string_view() const;
head(parse::capstan &pc, const headers::closure &c = {});
head() = default;
};

View file

@ -307,6 +307,24 @@ ircd::http::request::head::head(parse::capstan &pc,
{
}
ircd::http::request::head::operator
string_view()
const
{
const string_view request_line
{
static_cast<const line::request &>(*this)
};
if(request_line.empty() || headers.empty())
return request_line;
return string_view
{
request_line.begin(), headers.end()
};
}
ircd::http::response::response(window_buffer &out,
const code &code,
const size_t &content_length,
@ -639,6 +657,21 @@ catch(const qi::expectation_failure<const char *> &e)
throw_error(e);
}
ircd::http::line::request::operator
string_view()
const
{
if(method.empty())
return string_view{};
assert(!version.empty());
assert(method.begin() < version.end());
return string_view
{
method.begin(), version.end()
};
}
ircd::http::line::line(parse::capstan &pc)
:string_view{[&pc]
{