From 7b90404072b51d2ce01fad23f139bd24d1b4628c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 13 Mar 2015 23:01:55 +0900 Subject: [PATCH] nghttpx: Omit well-known port from hostport in downstream request --- src/shrpx_http2_session.cc | 4 ++++ src/util.cc | 6 ++++-- src/util.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 03f32d69..41732f5e 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -506,6 +506,10 @@ int Http2Session::downstream_connect_proxy() { std::string req = "CONNECT "; req += downstream_addr.hostport.get(); + if (downstream_addr.port == 80 || downstream_addr.port == 443) { + req += ":"; + req += util::utos(downstream_addr.port); + } req += " HTTP/1.1\r\nHost: "; req += downstream_addr.host.get(); req += "\r\n"; diff --git a/src/util.cc b/src/util.cc index 5683ded7..1b6ffb74 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1038,8 +1038,10 @@ std::string make_hostport(const char *host, uint16_t port) { hostport += "]"; } - hostport += ":"; - hostport += utos(port); + if (port != 80 && port != 443) { + hostport += ":"; + hostport += utos(port); + } return hostport; } diff --git a/src/util.h b/src/util.h index 3f68acc3..b30eb707 100644 --- a/src/util.h +++ b/src/util.h @@ -609,7 +609,7 @@ std::string format_duration(const std::chrono::microseconds &u); // Creates "host:port" string using given |host| and |port|. If // |host| is numeric IPv6 address (e.g., ::1), it is enclosed by "[" -// and "]". +// and "]". If |port| is 80 or 443, port part is omitted. std::string make_hostport(const char *host, uint16_t port); } // namespace util