From de0543f684e0a05dd8aba845fdcb1640ed8b0907 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 13 Mar 2015 22:52:09 +0900 Subject: [PATCH] nghttpx: Refactor a bit --- src/shrpx_http2_downstream_connection.cc | 9 +++++---- src/shrpx_http_downstream_connection.cc | 9 ++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index 6a66605b..98b9d8ec 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -261,15 +261,16 @@ int Http2DownstreamConnection::push_request_headers() { // http2session_ has already in CONNECTED state, so we can get // addr_idx here. auto addr_idx = http2session_->get_addr_idx(); - auto &downstream_addr = get_config()->downstream_addrs[addr_idx]; + auto downstream_hostport = + get_config()->downstream_addrs[addr_idx].hostport.get(); const char *authority = nullptr, *host = nullptr; if (!no_host_rewrite) { if (!downstream_->get_request_http2_authority().empty()) { - authority = downstream_addr.hostport.get(); + authority = downstream_hostport; } if (downstream_->get_request_header(http2::HD_HOST)) { - host = downstream_addr.hostport.get(); + host = downstream_hostport; } } else { if (!downstream_->get_request_http2_authority().empty()) { @@ -284,7 +285,7 @@ int Http2DownstreamConnection::push_request_headers() { if (!authority && !host) { // upstream is HTTP/1.0. We use backend server's host // nonetheless. - host = downstream_addr.hostport.get(); + host = downstream_hostport; } if (authority) { diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index c5c7341a..95b9e0ea 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -211,14 +211,17 @@ int HttpDownstreamConnection::attach_downstream(Downstream *downstream) { int HttpDownstreamConnection::push_request_headers() { const char *authority = nullptr, *host = nullptr; + auto downstream_hostport = + get_config()->downstream_addrs[addr_idx_].hostport.get(); + if (!get_config()->no_host_rewrite && !get_config()->http2_proxy && !get_config()->client_proxy && downstream_->get_request_method() != "CONNECT") { if (!downstream_->get_request_http2_authority().empty()) { - authority = get_config()->downstream_addrs[addr_idx_].hostport.get(); + authority = downstream_hostport; } if (downstream_->get_request_header(http2::HD_HOST)) { - host = get_config()->downstream_addrs[addr_idx_].hostport.get(); + host = downstream_hostport; } } else { if (!downstream_->get_request_http2_authority().empty()) { @@ -233,7 +236,7 @@ int HttpDownstreamConnection::push_request_headers() { if (!authority && !host) { // upstream is HTTP/1.0. We use backend server's host // nonetheless. - host = get_config()->downstream_addrs[addr_idx_].hostport.get(); + host = downstream_hostport; } if (authority) {