http2: handle trailing colon in authorityAddr

This change modifies the authorityAddr result for authorities with empty
port information, such as "example.com:". Previously, such authorities
passed through the function unchanged. This conflicts with the result
from net/http's canonicalAddr, which returns "example.com:443" (for
HTTPS).

net/http's canonicalAddr result is passed to http2's upgradeFn (defined
inside http2.configureTransports) from net/http's (*Transport).dialConn.
The connection is then added to http2's cache under the canonicalAddr
key. However, cache lookups are performed in (*Transport).RoundTripOpt
using the result from authorityAddr applied directly to the input URL.
The lookup thus fails if authorityAddr and canonicalAddr don't agree.

http2's lookup error propagates upwards to net/http's
(*Transport).roundTrip, where the request is retried. The end result is
an infinite loop of the request being repeated, each time with a freshly
dialed connection, that can only be stopped by a timeout.

Aligning the results of http2's authorityAddr and net/http's
canonicalAddr fixes the bug. While an authority with a trailing colon is
invalid per URL specifications, I have personally come across
misconfigured web servers emitting such URLs as redirects. This is how I
discovered this issue in http2.

Change-Id: If47aa61b8d256d76a3451090076e6eb5ff596c9e
GitHub-Last-Rev: cb0470115705139cfc60a3d27ec432363fd54a1c
GitHub-Pull-Request: golang/net#170
Reviewed-on: https://go-review.googlesource.com/c/net/+/487915
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2 files changed
tree: a6ef07ccf1ebc0c91cc99ba419f92744c1ce1cae
  1. bpf/
  2. context/
  3. dict/
  4. dns/
  5. html/
  6. http/
  7. http2/
  8. icmp/
  9. idna/
  10. internal/
  11. ipv4/
  12. ipv6/
  13. lif/
  14. nettest/
  15. netutil/
  16. proxy/
  17. publicsuffix/
  18. route/
  19. trace/
  20. webdav/
  21. websocket/
  22. xsrftoken/
  23. .gitattributes
  24. .gitignore
  25. codereview.cfg
  26. CONTRIBUTING.md
  27. go.mod
  28. go.sum
  29. LICENSE
  30. PATENTS
  31. README.md
README.md

Go Networking

Go Reference

This repository holds supplementary Go networking libraries.

Download/Install

The easiest way to install is to run go get -u golang.org/x/net. You can also manually git clone the repository to $GOPATH/src/golang.org/x/net.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html. The main issue tracker for the net repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/net:” in the subject line, so it is easy to find.