mirror of
https://github.com/nghttp2/nghttp2.git
synced 2025-12-06 18:18:52 +08:00
Adopt std::to_array and remove make_array
This commit is contained in:
@@ -925,12 +925,13 @@ int Http2Handler::submit_file_response(const StringRef &status, Stream *stream,
|
|||||||
const std::string *content_type,
|
const std::string *content_type,
|
||||||
nghttp2_data_provider2 *data_prd) {
|
nghttp2_data_provider2 *data_prd) {
|
||||||
std::string last_modified_str;
|
std::string last_modified_str;
|
||||||
auto nva = make_array(http2::make_nv_ls_nocopy(":status", status),
|
auto nva =
|
||||||
http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER),
|
std::to_array({http2::make_nv_ls_nocopy(":status", status),
|
||||||
http2::make_nv_ll("cache-control", "max-age=3600"),
|
http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER),
|
||||||
http2::make_nv_ls("date", sessions_->get_cached_date()),
|
http2::make_nv_ll("cache-control", "max-age=3600"),
|
||||||
http2::make_nv_ll("", ""), http2::make_nv_ll("", ""),
|
http2::make_nv_ls("date", sessions_->get_cached_date()),
|
||||||
http2::make_nv_ll("", ""), http2::make_nv_ll("", ""));
|
http2::make_nv_ll("", ""), http2::make_nv_ll("", ""),
|
||||||
|
http2::make_nv_ll("", ""), http2::make_nv_ll("", "")});
|
||||||
size_t nvlen = 4;
|
size_t nvlen = 4;
|
||||||
if (!get_config()->no_content_length) {
|
if (!get_config()->no_content_length) {
|
||||||
nva[nvlen++] = http2::make_nv_ls_nocopy(
|
nva[nvlen++] = http2::make_nv_ls_nocopy(
|
||||||
@@ -978,10 +979,11 @@ int Http2Handler::submit_response(const StringRef &status, int32_t stream_id,
|
|||||||
|
|
||||||
int Http2Handler::submit_response(const StringRef &status, int32_t stream_id,
|
int Http2Handler::submit_response(const StringRef &status, int32_t stream_id,
|
||||||
nghttp2_data_provider2 *data_prd) {
|
nghttp2_data_provider2 *data_prd) {
|
||||||
auto nva = make_array(http2::make_nv_ls_nocopy(":status", status),
|
auto nva =
|
||||||
http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER),
|
std::to_array({http2::make_nv_ls_nocopy(":status", status),
|
||||||
http2::make_nv_ls("date", sessions_->get_cached_date()),
|
http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER),
|
||||||
http2::make_nv_ll("", ""));
|
http2::make_nv_ls("date", sessions_->get_cached_date()),
|
||||||
|
http2::make_nv_ll("", "")});
|
||||||
size_t nvlen = 3;
|
size_t nvlen = 3;
|
||||||
|
|
||||||
if (data_prd) {
|
if (data_prd) {
|
||||||
@@ -997,7 +999,7 @@ int Http2Handler::submit_response(const StringRef &status, int32_t stream_id,
|
|||||||
|
|
||||||
int Http2Handler::submit_non_final_response(const std::string &status,
|
int Http2Handler::submit_non_final_response(const std::string &status,
|
||||||
int32_t stream_id) {
|
int32_t stream_id) {
|
||||||
auto nva = make_array(http2::make_nv_ls(":status", status));
|
auto nva = std::to_array({http2::make_nv_ls(":status", status)});
|
||||||
return nghttp2_submit_headers(session_, NGHTTP2_FLAG_NONE, stream_id, nullptr,
|
return nghttp2_submit_headers(session_, NGHTTP2_FLAG_NONE, stream_id, nullptr,
|
||||||
nva.data(), nva.size(), nullptr);
|
nva.data(), nva.size(), nullptr);
|
||||||
}
|
}
|
||||||
@@ -1013,10 +1015,10 @@ int Http2Handler::submit_push_promise(Stream *stream,
|
|||||||
auto scheme = get_config()->no_tls ? StringRef::from_lit("http")
|
auto scheme = get_config()->no_tls ? StringRef::from_lit("http")
|
||||||
: StringRef::from_lit("https");
|
: StringRef::from_lit("https");
|
||||||
|
|
||||||
auto nva = make_array(http2::make_nv_ll(":method", "GET"),
|
auto nva = std::to_array({http2::make_nv_ll(":method", "GET"),
|
||||||
http2::make_nv_ls_nocopy(":path", push_path),
|
http2::make_nv_ls_nocopy(":path", push_path),
|
||||||
http2::make_nv_ls_nocopy(":scheme", scheme),
|
http2::make_nv_ls_nocopy(":scheme", scheme),
|
||||||
http2::make_nv_ls_nocopy(":authority", authority));
|
http2::make_nv_ls_nocopy(":authority", authority)});
|
||||||
|
|
||||||
auto promised_stream_id = nghttp2_submit_push_promise(
|
auto promised_stream_id = nghttp2_submit_push_promise(
|
||||||
session_, NGHTTP2_FLAG_END_HEADERS, stream->stream_id, nva.data(),
|
session_, NGHTTP2_FLAG_END_HEADERS, stream->stream_id, nva.data(),
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
@@ -2991,8 +2992,8 @@ int main(int argc, char **argv) {
|
|||||||
shared_nva.emplace_back("user-agent", user_agent);
|
shared_nva.emplace_back("user-agent", user_agent);
|
||||||
|
|
||||||
// list header fields that can be overridden.
|
// list header fields that can be overridden.
|
||||||
auto override_hdrs = make_array<std::string>(":authority", "host", ":method",
|
auto override_hdrs = std::to_array<std::string_view>(
|
||||||
":scheme", "user-agent");
|
{":authority", "host", ":method", ":scheme", "user-agent"});
|
||||||
|
|
||||||
for (auto &kv : config.custom_headers) {
|
for (auto &kv : config.custom_headers) {
|
||||||
if (std::find(std::begin(override_hdrs), std::end(override_hdrs),
|
if (std::find(std::begin(override_hdrs), std::end(override_hdrs),
|
||||||
|
|||||||
@@ -89,13 +89,13 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr auto anchors = std::array<Anchor, 5>{{
|
constexpr auto anchors = std::to_array<Anchor>({
|
||||||
{3, 0, 201},
|
{3, 0, 201},
|
||||||
{5, 0, 101},
|
{5, 0, 101},
|
||||||
{7, 0, 1},
|
{7, 0, 1},
|
||||||
{9, 7, 1},
|
{9, 7, 1},
|
||||||
{11, 3, 1},
|
{11, 3, 1},
|
||||||
}};
|
});
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Config::Config()
|
Config::Config()
|
||||||
|
|||||||
@@ -1324,7 +1324,7 @@ int ClientHandler::proxy_protocol_read() {
|
|||||||
// NULL character really destroys functions which expects NULL
|
// NULL character really destroys functions which expects NULL
|
||||||
// terminated string. We won't expect it in PROXY protocol line, so
|
// terminated string. We won't expect it in PROXY protocol line, so
|
||||||
// find it here.
|
// find it here.
|
||||||
auto chrs = std::array<char, 2>{'\n', '\0'};
|
auto chrs = std::to_array({'\n', '\0'});
|
||||||
|
|
||||||
constexpr size_t MAX_PROXY_LINELEN = 107;
|
constexpr size_t MAX_PROXY_LINELEN = 107;
|
||||||
|
|
||||||
|
|||||||
@@ -1600,12 +1600,12 @@ int Http2Upstream::error_reply(Downstream *downstream,
|
|||||||
auto content_length = util::make_string_ref_uint(balloc, html.size());
|
auto content_length = util::make_string_ref_uint(balloc, html.size());
|
||||||
auto date = make_string_ref(balloc, lgconf->tstamp->time_http);
|
auto date = make_string_ref(balloc, lgconf->tstamp->time_http);
|
||||||
|
|
||||||
auto nva = std::array<nghttp2_nv, 5>{
|
auto nva = std::to_array(
|
||||||
{http2::make_nv_ls_nocopy(":status", response_status),
|
{http2::make_nv_ls_nocopy(":status", response_status),
|
||||||
http2::make_nv_ll("content-type", "text/html; charset=UTF-8"),
|
http2::make_nv_ll("content-type", "text/html; charset=UTF-8"),
|
||||||
http2::make_nv_ls_nocopy("server", get_config()->http.server_name),
|
http2::make_nv_ls_nocopy("server", get_config()->http.server_name),
|
||||||
http2::make_nv_ls_nocopy("content-length", content_length),
|
http2::make_nv_ls_nocopy("content-length", content_length),
|
||||||
http2::make_nv_ls_nocopy("date", date)}};
|
http2::make_nv_ls_nocopy("date", date)});
|
||||||
|
|
||||||
rv = nghttp2_submit_response2(session_, downstream->get_stream_id(),
|
rv = nghttp2_submit_response2(session_, downstream->get_stream_id(),
|
||||||
nva.data(), nva.size(), &data_prd);
|
nva.data(), nva.size(), &data_prd);
|
||||||
|
|||||||
@@ -2738,12 +2738,12 @@ int Http3Upstream::error_reply(Downstream *downstream,
|
|||||||
auto content_length = util::make_string_ref_uint(balloc, html.size());
|
auto content_length = util::make_string_ref_uint(balloc, html.size());
|
||||||
auto date = make_string_ref(balloc, lgconf->tstamp->time_http);
|
auto date = make_string_ref(balloc, lgconf->tstamp->time_http);
|
||||||
|
|
||||||
auto nva = std::array<nghttp3_nv, 5>{
|
auto nva = std::to_array(
|
||||||
{http3::make_nv_ls_nocopy(":status", response_status),
|
{http3::make_nv_ls_nocopy(":status", response_status),
|
||||||
http3::make_nv_ll("content-type", "text/html; charset=UTF-8"),
|
http3::make_nv_ll("content-type", "text/html; charset=UTF-8"),
|
||||||
http3::make_nv_ls_nocopy("server", get_config()->http.server_name),
|
http3::make_nv_ls_nocopy("server", get_config()->http.server_name),
|
||||||
http3::make_nv_ls_nocopy("content-length", content_length),
|
http3::make_nv_ls_nocopy("content-length", content_length),
|
||||||
http3::make_nv_ls_nocopy("date", date)}};
|
http3::make_nv_ls_nocopy("date", date)});
|
||||||
|
|
||||||
rv = nghttp3_conn_submit_response(httpconn_, downstream->get_stream_id(),
|
rv = nghttp3_conn_submit_response(httpconn_, downstream->get_stream_id(),
|
||||||
nva.data(), nva.size(), &data_read);
|
nva.data(), nva.size(), &data_read);
|
||||||
|
|||||||
@@ -531,10 +531,10 @@ int QUICConnectionHandler::send_version_negotiation(
|
|||||||
const UpstreamAddr *faddr, uint32_t version, const uint8_t *ini_dcid,
|
const UpstreamAddr *faddr, uint32_t version, const uint8_t *ini_dcid,
|
||||||
size_t ini_dcidlen, const uint8_t *ini_scid, size_t ini_scidlen,
|
size_t ini_dcidlen, const uint8_t *ini_scid, size_t ini_scidlen,
|
||||||
const Address &remote_addr, const Address &local_addr) {
|
const Address &remote_addr, const Address &local_addr) {
|
||||||
std::array<uint32_t, 2> sv{
|
auto sv = std::to_array({
|
||||||
generate_reserved_version(remote_addr, version),
|
generate_reserved_version(remote_addr, version),
|
||||||
NGTCP2_PROTO_VER_V1,
|
NGTCP2_PROTO_VER_V1,
|
||||||
};
|
});
|
||||||
|
|
||||||
std::array<uint8_t, NGTCP2_MAX_UDP_PAYLOAD_SIZE> buf;
|
std::array<uint8_t, NGTCP2_MAX_UDP_PAYLOAD_SIZE> buf;
|
||||||
|
|
||||||
|
|||||||
@@ -113,14 +113,14 @@ void test_shrpx_router_match(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test_shrpx_router_match_wildcard(void) {
|
void test_shrpx_router_match_wildcard(void) {
|
||||||
constexpr auto patterns = std::array<Pattern, 6>{{
|
constexpr auto patterns = std::to_array<Pattern>({
|
||||||
{StringRef::from_lit("nghttp2.org/"), 0},
|
{StringRef::from_lit("nghttp2.org/"), 0},
|
||||||
{StringRef::from_lit("nghttp2.org/"), 1, true},
|
{StringRef::from_lit("nghttp2.org/"), 1, true},
|
||||||
{StringRef::from_lit("nghttp2.org/alpha/"), 2},
|
{StringRef::from_lit("nghttp2.org/alpha/"), 2},
|
||||||
{StringRef::from_lit("nghttp2.org/alpha/"), 3, true},
|
{StringRef::from_lit("nghttp2.org/alpha/"), 3, true},
|
||||||
{StringRef::from_lit("nghttp2.org/bravo"), 4},
|
{StringRef::from_lit("nghttp2.org/bravo"), 4},
|
||||||
{StringRef::from_lit("nghttp2.org/bravo"), 5, true},
|
{StringRef::from_lit("nghttp2.org/bravo"), 5, true},
|
||||||
}};
|
});
|
||||||
|
|
||||||
Router router;
|
Router router;
|
||||||
|
|
||||||
|
|||||||
@@ -110,13 +110,13 @@ int signal_set_handler(void (*handler)(int), Signals &&sigs) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr auto main_proc_ign_signals = std::array<int, 1>{SIGPIPE};
|
constexpr auto main_proc_ign_signals = std::to_array({SIGPIPE});
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr auto worker_proc_ign_signals =
|
constexpr auto worker_proc_ign_signals =
|
||||||
std::array<int, 5>{REOPEN_LOG_SIGNAL, EXEC_BINARY_SIGNAL,
|
std::to_array({REOPEN_LOG_SIGNAL, EXEC_BINARY_SIGNAL,
|
||||||
GRACEFUL_SHUTDOWN_SIGNAL, RELOAD_SIGNAL, SIGPIPE};
|
GRACEFUL_SHUTDOWN_SIGNAL, RELOAD_SIGNAL, SIGPIPE});
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int shrpx_signal_set_main_proc_ign_handler() {
|
int shrpx_signal_set_main_proc_ign_handler() {
|
||||||
|
|||||||
@@ -559,14 +559,14 @@ int ticket_key_cb(SSL *ssl, unsigned char *key_name, unsigned char *iv,
|
|||||||
EVP_EncryptInit_ex(ctx, get_config()->tls.ticket.cipher, nullptr,
|
EVP_EncryptInit_ex(ctx, get_config()->tls.ticket.cipher, nullptr,
|
||||||
key.data.enc_key.data(), iv);
|
key.data.enc_key.data(), iv);
|
||||||
#if OPENSSL_3_0_0_API
|
#if OPENSSL_3_0_0_API
|
||||||
std::array<OSSL_PARAM, 3> params{
|
auto params = std::to_array({
|
||||||
OSSL_PARAM_construct_octet_string(
|
OSSL_PARAM_construct_octet_string(
|
||||||
OSSL_MAC_PARAM_KEY, key.data.hmac_key.data(), key.hmac_keylen),
|
OSSL_MAC_PARAM_KEY, key.data.hmac_key.data(), key.hmac_keylen),
|
||||||
OSSL_PARAM_construct_utf8_string(
|
OSSL_PARAM_construct_utf8_string(
|
||||||
OSSL_MAC_PARAM_DIGEST,
|
OSSL_MAC_PARAM_DIGEST,
|
||||||
const_cast<char *>(EVP_MD_get0_name(key.hmac)), 0),
|
const_cast<char *>(EVP_MD_get0_name(key.hmac)), 0),
|
||||||
OSSL_PARAM_construct_end(),
|
OSSL_PARAM_construct_end(),
|
||||||
};
|
});
|
||||||
if (!EVP_MAC_CTX_set_params(hctx, params.data())) {
|
if (!EVP_MAC_CTX_set_params(hctx, params.data())) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
CLOG(INFO, handler) << "EVP_MAC_CTX_set_params failed";
|
CLOG(INFO, handler) << "EVP_MAC_CTX_set_params failed";
|
||||||
@@ -604,14 +604,14 @@ int ticket_key_cb(SSL *ssl, unsigned char *key_name, unsigned char *iv,
|
|||||||
|
|
||||||
auto &key = keys[i];
|
auto &key = keys[i];
|
||||||
#if OPENSSL_3_0_0_API
|
#if OPENSSL_3_0_0_API
|
||||||
std::array<OSSL_PARAM, 3> params{
|
auto params = std::to_array({
|
||||||
OSSL_PARAM_construct_octet_string(
|
OSSL_PARAM_construct_octet_string(
|
||||||
OSSL_MAC_PARAM_KEY, key.data.hmac_key.data(), key.hmac_keylen),
|
OSSL_MAC_PARAM_KEY, key.data.hmac_key.data(), key.hmac_keylen),
|
||||||
OSSL_PARAM_construct_utf8_string(
|
OSSL_PARAM_construct_utf8_string(
|
||||||
OSSL_MAC_PARAM_DIGEST, const_cast<char *>(EVP_MD_get0_name(key.hmac)),
|
OSSL_MAC_PARAM_DIGEST, const_cast<char *>(EVP_MD_get0_name(key.hmac)),
|
||||||
0),
|
0),
|
||||||
OSSL_PARAM_construct_end(),
|
OSSL_PARAM_construct_end(),
|
||||||
};
|
});
|
||||||
if (!EVP_MAC_CTX_set_params(hctx, params.data())) {
|
if (!EVP_MAC_CTX_set_params(hctx, params.data())) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
CLOG(INFO, handler) << "EVP_MAC_CTX_set_params failed";
|
CLOG(INFO, handler) << "EVP_MAC_CTX_set_params failed";
|
||||||
|
|||||||
@@ -40,17 +40,6 @@
|
|||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
|
|
||||||
// std::forward is constexpr since C++14
|
|
||||||
template <typename... T>
|
|
||||||
constexpr std::array<
|
|
||||||
typename std::decay<typename std::common_type<T...>::type>::type,
|
|
||||||
sizeof...(T)>
|
|
||||||
make_array(T &&...t) {
|
|
||||||
return std::array<
|
|
||||||
typename std::decay<typename std::common_type<T...>::type>::type,
|
|
||||||
sizeof...(T)>{{std::forward<T>(t)...}};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, size_t N> constexpr size_t array_size(T (&)[N]) {
|
template <typename T, size_t N> constexpr size_t array_size(T (&)[N]) {
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -562,16 +562,16 @@ void test_util_localtime_date(void) {
|
|||||||
|
|
||||||
void test_util_get_uint64(void) {
|
void test_util_get_uint64(void) {
|
||||||
{
|
{
|
||||||
auto v = std::array<unsigned char, 8>{
|
auto v = std::to_array<unsigned char>(
|
||||||
{0x01, 0x12, 0x34, 0x56, 0xff, 0x9a, 0xab, 0xbc}};
|
{0x01, 0x12, 0x34, 0x56, 0xff, 0x9a, 0xab, 0xbc});
|
||||||
|
|
||||||
auto n = util::get_uint64(v.data());
|
auto n = util::get_uint64(v.data());
|
||||||
|
|
||||||
assert_uint64(0x01123456ff9aabbcULL, ==, n);
|
assert_uint64(0x01123456ff9aabbcULL, ==, n);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto v = std::array<unsigned char, 8>{
|
auto v = std::to_array<unsigned char>(
|
||||||
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
|
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff});
|
||||||
|
|
||||||
auto n = util::get_uint64(v.data());
|
auto n = util::get_uint64(v.data());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user