nghttpx: More StringRef-fy
This commit is contained in:
parent
a9e365ad7d
commit
186d440168
22
src/shrpx.cc
22
src/shrpx.cc
|
@ -1011,27 +1011,27 @@ bool conf_exists(const char *path) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char DEFAULT_NPN_LIST[] = "h2,h2-16,h2-14,"
|
constexpr auto DEFAULT_NPN_LIST = StringRef::from_lit("h2,h2-16,h2-14,"
|
||||||
#ifdef HAVE_SPDYLAY
|
#ifdef HAVE_SPDYLAY
|
||||||
"spdy/3.1,"
|
"spdy/3.1,"
|
||||||
#endif // HAVE_SPDYLAY
|
#endif // HAVE_SPDYLAY
|
||||||
"http/1.1";
|
"http/1.1");
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char DEFAULT_TLS_PROTO_LIST[] = "TLSv1.2,TLSv1.1";
|
constexpr auto DEFAULT_TLS_PROTO_LIST = StringRef::from_lit("TLSv1.2,TLSv1.1");
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char DEFAULT_ACCESSLOG_FORMAT[] =
|
constexpr auto DEFAULT_ACCESSLOG_FORMAT = StringRef::from_lit(
|
||||||
R"($remote_addr - - [$time_local] )"
|
R"($remote_addr - - [$time_local] )"
|
||||||
R"("$request" $status $body_bytes_sent )"
|
R"("$request" $status $body_bytes_sent )"
|
||||||
R"("$http_referer" "$http_user_agent")";
|
R"("$http_referer" "$http_user_agent")");
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char DEFAULT_DOWNSTREAM_HOST[] = "127.0.0.1";
|
constexpr char DEFAULT_DOWNSTREAM_HOST[] = "127.0.0.1";
|
||||||
int16_t DEFAULT_DOWNSTREAM_PORT = 80;
|
constexpr int16_t DEFAULT_DOWNSTREAM_PORT = 80;
|
||||||
} // namespace;
|
} // namespace;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -1117,8 +1117,7 @@ void fill_default_config() {
|
||||||
auto &loggingconf = mod_config()->logging;
|
auto &loggingconf = mod_config()->logging;
|
||||||
{
|
{
|
||||||
auto &accessconf = loggingconf.access;
|
auto &accessconf = loggingconf.access;
|
||||||
accessconf.format =
|
accessconf.format = parse_log_format(DEFAULT_ACCESSLOG_FORMAT);
|
||||||
parse_log_format(StringRef::from_lit(DEFAULT_ACCESSLOG_FORMAT));
|
|
||||||
|
|
||||||
auto &errorconf = loggingconf.error;
|
auto &errorconf = loggingconf.error;
|
||||||
errorconf.file = "/dev/stderr";
|
errorconf.file = "/dev/stderr";
|
||||||
|
@ -2025,12 +2024,11 @@ void process_options(int argc, char **argv,
|
||||||
auto &tlsconf = mod_config()->tls;
|
auto &tlsconf = mod_config()->tls;
|
||||||
|
|
||||||
if (tlsconf.npn_list.empty()) {
|
if (tlsconf.npn_list.empty()) {
|
||||||
tlsconf.npn_list =
|
tlsconf.npn_list = util::parse_config_str_list(DEFAULT_NPN_LIST);
|
||||||
util::parse_config_str_list(StringRef::from_lit(DEFAULT_NPN_LIST));
|
|
||||||
}
|
}
|
||||||
if (tlsconf.tls_proto_list.empty()) {
|
if (tlsconf.tls_proto_list.empty()) {
|
||||||
tlsconf.tls_proto_list = util::parse_config_str_list(
|
tlsconf.tls_proto_list =
|
||||||
StringRef::from_lit(DEFAULT_TLS_PROTO_LIST));
|
util::parse_config_str_list(DEFAULT_TLS_PROTO_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsconf.tls_proto_mask = ssl::create_tls_proto_mask(tlsconf.tls_proto_list);
|
tlsconf.tls_proto_mask = ssl::create_tls_proto_mask(tlsconf.tls_proto_list);
|
||||||
|
|
|
@ -809,12 +809,6 @@ int ClientHandler::perform_http2_upgrade(HttpsUpstream *http) {
|
||||||
auto downstream = http->get_downstream();
|
auto downstream = http->get_downstream();
|
||||||
auto input = downstream->get_response_buf();
|
auto input = downstream->get_response_buf();
|
||||||
|
|
||||||
static constexpr char res[] =
|
|
||||||
"HTTP/1.1 101 Switching Protocols\r\n"
|
|
||||||
"Connection: Upgrade\r\n"
|
|
||||||
"Upgrade: " NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "\r\n"
|
|
||||||
"\r\n";
|
|
||||||
|
|
||||||
if (upstream->upgrade_upstream(http) != 0) {
|
if (upstream->upgrade_upstream(http) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -827,7 +821,14 @@ int ClientHandler::perform_http2_upgrade(HttpsUpstream *http) {
|
||||||
write_ = &ClientHandler::write_clear;
|
write_ = &ClientHandler::write_clear;
|
||||||
|
|
||||||
input->remove(*output, input->rleft());
|
input->remove(*output, input->rleft());
|
||||||
output->append(res, str_size(res));
|
|
||||||
|
constexpr auto res =
|
||||||
|
StringRef::from_lit("HTTP/1.1 101 Switching Protocols\r\n"
|
||||||
|
"Connection: Upgrade\r\n"
|
||||||
|
"Upgrade: " NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "\r\n"
|
||||||
|
"\r\n");
|
||||||
|
|
||||||
|
output->append(res);
|
||||||
upstream_ = std::move(upstream);
|
upstream_ = std::move(upstream);
|
||||||
|
|
||||||
signal_write();
|
signal_write();
|
||||||
|
@ -1030,23 +1031,23 @@ int ClientHandler::proxy_protocol_read() {
|
||||||
|
|
||||||
--end;
|
--end;
|
||||||
|
|
||||||
constexpr char HEADER[] = "PROXY ";
|
constexpr auto HEADER = StringRef::from_lit("PROXY ");
|
||||||
|
|
||||||
if (static_cast<size_t>(end - rb_.pos) < str_size(HEADER)) {
|
if (static_cast<size_t>(end - rb_.pos) < HEADER.size()) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
CLOG(INFO, this) << "PROXY-protocol-v1: PROXY version 1 ID not found";
|
CLOG(INFO, this) << "PROXY-protocol-v1: PROXY version 1 ID not found";
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!util::streq_l(HEADER, rb_.pos, str_size(HEADER))) {
|
if (!util::streq(HEADER, StringRef{rb_.pos, HEADER.size()})) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
CLOG(INFO, this) << "PROXY-protocol-v1: Bad PROXY protocol version 1 ID";
|
CLOG(INFO, this) << "PROXY-protocol-v1: Bad PROXY protocol version 1 ID";
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_.drain(str_size(HEADER));
|
rb_.drain(HEADER.size());
|
||||||
|
|
||||||
int family;
|
int family;
|
||||||
|
|
||||||
|
|
|
@ -193,8 +193,8 @@ int ocsp_resp_cb(SSL *ssl, void *arg) {
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif // OPENSSL_IS_BORINGSSL
|
#endif // OPENSSL_IS_BORINGSSL
|
||||||
|
|
||||||
constexpr char MEMCACHED_SESSION_CACHE_KEY_PREFIX[] =
|
constexpr auto MEMCACHED_SESSION_CACHE_KEY_PREFIX =
|
||||||
"nghttpx:tls-session-cache:";
|
StringRef::from_lit("nghttpx:tls-session-cache:");
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int tls_session_new_cb(SSL *ssl, SSL_SESSION *session) {
|
int tls_session_new_cb(SSL *ssl, SSL_SESSION *session) {
|
||||||
|
@ -214,7 +214,7 @@ int tls_session_new_cb(SSL *ssl, SSL_SESSION *session) {
|
||||||
|
|
||||||
auto req = make_unique<MemcachedRequest>();
|
auto req = make_unique<MemcachedRequest>();
|
||||||
req->op = MEMCACHED_OP_ADD;
|
req->op = MEMCACHED_OP_ADD;
|
||||||
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX;
|
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
||||||
req->key += util::format_hex(id, idlen);
|
req->key += util::format_hex(id, idlen);
|
||||||
|
|
||||||
auto sessionlen = i2d_SSL_SESSION(session, nullptr);
|
auto sessionlen = i2d_SSL_SESSION(session, nullptr);
|
||||||
|
@ -271,7 +271,7 @@ SSL_SESSION *tls_session_get_cb(SSL *ssl, unsigned char *id, int idlen,
|
||||||
|
|
||||||
auto req = make_unique<MemcachedRequest>();
|
auto req = make_unique<MemcachedRequest>();
|
||||||
req->op = MEMCACHED_OP_GET;
|
req->op = MEMCACHED_OP_GET;
|
||||||
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX;
|
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
||||||
req->key += util::format_hex(id, idlen);
|
req->key += util::format_hex(id, idlen);
|
||||||
req->cb = [conn](MemcachedRequest *, MemcachedResult res) {
|
req->cb = [conn](MemcachedRequest *, MemcachedResult res) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
|
|
Loading…
Reference in New Issue