mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +01:00
ircd::http: Burning desire to dedupe this.
This commit is contained in:
parent
2a65c17ce3
commit
ebb48d96a9
1 changed files with 24 additions and 32 deletions
56
ircd/http.cc
56
ircd/http.cc
|
@ -49,6 +49,8 @@ namespace ircd::http
|
|||
struct parser extern const parser;
|
||||
|
||||
extern const std::unordered_map<ircd::http::code, ircd::string_view> reason;
|
||||
|
||||
[[noreturn]] void throw_error(const qi::expectation_failure<const char *> &);
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT
|
||||
|
@ -618,22 +620,7 @@ try
|
|||
}
|
||||
catch(const qi::expectation_failure<const char *> &e)
|
||||
{
|
||||
const auto rule
|
||||
{
|
||||
ircd::string(e.what_)
|
||||
};
|
||||
|
||||
throw error
|
||||
{
|
||||
code::BAD_REQUEST, fmt::snstringf
|
||||
{
|
||||
BUFSIZE,
|
||||
"I require a valid HTTP %s. You sent %zu invalid characters starting with `%s'.",
|
||||
between(rule, "<", ">"),
|
||||
size_t(e.last - e.first),
|
||||
string_view{e.first, e.last}
|
||||
}
|
||||
};
|
||||
throw_error(e);
|
||||
}
|
||||
|
||||
ircd::http::line::response::response(const line &line)
|
||||
|
@ -662,22 +649,7 @@ try
|
|||
}
|
||||
catch(const qi::expectation_failure<const char *> &e)
|
||||
{
|
||||
const auto rule
|
||||
{
|
||||
ircd::string(e.what_)
|
||||
};
|
||||
|
||||
throw error
|
||||
{
|
||||
code::BAD_REQUEST, fmt::snstringf
|
||||
{
|
||||
BUFSIZE,
|
||||
"I require a valid HTTP %s. You sent %zu invalid characters starting with `%s'.",
|
||||
between(rule, "<", ">"),
|
||||
size_t(e.last - e.first),
|
||||
string_view{e.first, e.last}
|
||||
}
|
||||
};
|
||||
throw_error(e);
|
||||
}
|
||||
|
||||
ircd::http::line::line(parse::capstan &pc)
|
||||
|
@ -880,6 +852,26 @@ ircd::http::writeline(stream_buffer &write)
|
|||
});
|
||||
}
|
||||
|
||||
void
|
||||
ircd::http::throw_error(const qi::expectation_failure<const char *> &e)
|
||||
{
|
||||
const auto rule
|
||||
{
|
||||
ircd::string(e.what_)
|
||||
};
|
||||
|
||||
throw error
|
||||
{
|
||||
code::BAD_REQUEST, fmt::snstringf
|
||||
{
|
||||
512, "I require a valid HTTP %s. You sent %zu invalid characters starting with `%s'.",
|
||||
between(rule, "<", ">"),
|
||||
size_t(e.last - e.first),
|
||||
string_view{e.first, e.last}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ircd::http::error::error(const enum code &code,
|
||||
std::string content,
|
||||
const vector_view<const header> &headers)
|
||||
|
|
Loading…
Reference in a new issue