From 17ccbae084645a189626da92e49c31ddb90afdad Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 25 Mar 2016 00:07:21 +0900 Subject: [PATCH] src: Don't compare against c-string --- src/HttpServer.cc | 5 +++-- src/shrpx.cc | 9 +++++---- src/shrpx_config.cc | 2 +- src/shrpx_http2_upstream.cc | 3 ++- src/shrpx_https_upstream.cc | 2 +- src/shrpx_spdy_upstream.cc | 3 ++- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index a3770e07..9c076f2c 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -1354,7 +1354,7 @@ void prepare_response(Stream *stream, Http2Handler *hd, } auto method = stream->header.method; - if (method == "HEAD") { + if (method == StringRef::from_lit("HEAD")) { hd->submit_file_response(StringRef::from_lit("200"), stream, file_ent->mtime, file_ent->length, file_ent->content_type, nullptr); @@ -1512,7 +1512,8 @@ int hd_on_frame_recv_callback(nghttp2_session *session, auto method = stream->header.method; if (hd->get_config()->echo_upload && - (method == "POST" || method == "PUT")) { + (method == StringRef::from_lit("POST") || + method == StringRef::from_lit("PUT"))) { if (!prepare_upload_temp_store(stream, hd)) { hd->submit_rst_stream(stream, NGHTTP2_INTERNAL_ERROR); return 0; diff --git a/src/shrpx.cc b/src/shrpx.cc index 8da4fafe..a4434707 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -524,7 +524,8 @@ int create_tcp_server_socket(UpstreamAddr &faddr, hints.ai_flags |= AI_ADDRCONFIG; #endif // AI_ADDRCONFIG - auto node = faddr.host == "*" ? nullptr : faddr.host.c_str(); + auto node = + faddr.host == StringRef::from_lit("*") ? nullptr : faddr.host.c_str(); addrinfo *res, *rp; rv = getaddrinfo(node, service.c_str(), &hints, &res); @@ -720,7 +721,7 @@ int create_acceptor_socket() { auto type = StringRef(env, end_type); auto value = end_type + 1; - if (type == "unix") { + if (type == StringRef::from_lit("unix")) { auto endfd = strchr(value, ','); if (!endfd) { continue; @@ -752,7 +753,7 @@ int create_acceptor_socket() { iaddrs.push_back(std::move(addr)); } - if (type == "tcp") { + if (type == StringRef::from_lit("tcp")) { auto fd = util::parse_uint(value); if (fd == -1) { LOG(WARN) << "Could not parse file descriptor from " << value; @@ -2132,7 +2133,7 @@ void process_options(int argc, char **argv, ssize_t catch_all_group = -1; for (size_t i = 0; i < addr_groups.size(); ++i) { auto &g = addr_groups[i]; - if (g.pattern == "/") { + if (g.pattern == StringRef::from_lit("/")) { catch_all_group = i; } if (LOG_ENABLED(INFO)) { diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 2ca55127..c259a137 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -831,7 +831,7 @@ int parse_error_page(std::vector &error_pages, const StringRef &opt, auto codestr = StringRef{std::begin(optarg), eq}; unsigned int code; - if (codestr == "*") { + if (codestr == StringRef::from_lit("*")) { code = 0; } else { auto n = util::parse_uint(codestr); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 12788227..dc258b94 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -325,7 +325,8 @@ int Http2Upstream::on_request_headers(Downstream *downstream, } if (path) { - if (method_token == HTTP_OPTIONS && path->value == "*") { + if (method_token == HTTP_OPTIONS && + path->value == StringRef::from_lit("*")) { // Server-wide OPTIONS request. Path is empty. } else if (get_config()->http2_proxy) { req.path = path->value; diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index f2236731..2501c116 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -354,7 +354,7 @@ int htp_hdrs_completecb(http_parser *htp) { req.no_authority = true; - if (method == HTTP_OPTIONS && req.path == "*") { + if (method == HTTP_OPTIONS && req.path == StringRef::from_lit("*")) { req.path = StringRef{}; } else { req.path = http2::rewrite_clean_path(balloc, req.path); diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index a3d002b5..040b5f6e 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -272,7 +272,8 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type, req.authority = host->value; if (get_config()->http2_proxy) { req.path = path->value; - } else if (method_token == HTTP_OPTIONS && path->value == "*") { + } else if (method_token == HTTP_OPTIONS && + path->value == StringRef::from_lit("*")) { // Server-wide OPTIONS request. Path is empty. } else { req.path = http2::rewrite_clean_path(balloc, path->value);