mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::http: Add format string construction for http::error.
This commit is contained in:
parent
d6241c66de
commit
10b8db0bb3
3 changed files with 29 additions and 5 deletions
|
@ -50,6 +50,7 @@ struct ircd::http::error
|
|||
error() = default;
|
||||
error(const http::code &, std::string content = {}, std::string headers = {});
|
||||
error(const http::code &, std::string content, const vector_view<const header> &);
|
||||
template<class... args> error(const http::code &, const char *const &fmt, args&&...);
|
||||
};
|
||||
|
||||
/// Represents a single \r\n delimited line used in HTTP.
|
||||
|
@ -331,3 +332,16 @@ const
|
|||
{
|
||||
return lex_cast<T>(at(key));
|
||||
}
|
||||
|
||||
template<class... args>
|
||||
ircd::http::error::error(const http::code &code,
|
||||
const char *const &fmt,
|
||||
args&&... a)
|
||||
:http::error
|
||||
{
|
||||
code, fmt::snstringf
|
||||
{
|
||||
BUFSIZE, fmt, std::forward<args>(a)...
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
|
@ -58,8 +58,8 @@ namespace ircd
|
|||
#include "json/json.h"
|
||||
//#include "cbor/cbor.h"
|
||||
#include "openssl.h"
|
||||
#include "http.h"
|
||||
#include "fmt.h"
|
||||
#include "http.h"
|
||||
#include "magics.h"
|
||||
#include "conf.h"
|
||||
#include "fs/fs.h"
|
||||
|
|
18
ircd/http.cc
18
ircd/http.cc
|
@ -763,12 +763,22 @@ ircd::http::error::error(const http::code &code,
|
|||
ircd::http::error::error(const http::code &code,
|
||||
std::string content,
|
||||
std::string headers)
|
||||
:ircd::error{generate_skip}
|
||||
,content{std::move(content)}
|
||||
,headers{std::move(headers)}
|
||||
:ircd::error
|
||||
{
|
||||
generate_skip
|
||||
}
|
||||
,content
|
||||
{
|
||||
std::move(content)
|
||||
}
|
||||
,headers
|
||||
{
|
||||
std::move(headers)
|
||||
}
|
||||
,code{code}
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%u %s", uint(code), status(code).c_str());
|
||||
auto &buf(ircd::error::buf);
|
||||
::snprintf(buf, sizeof(buf), "%u %s", uint(code), status(code).c_str());
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue