2016-11-08 01:13:56 +00:00
|
|
|
package challenge
|
2016-09-01 21:46:31 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-09-19 21:14:07 +00:00
|
|
|
// FROM: https://golang.org/src/net/http/http.go
|
2016-09-01 21:46:31 +00:00
|
|
|
// Given a string of the form "host", "host:port", or "[ipv6::address]:port",
|
|
|
|
// return true if the string includes a port.
|
|
|
|
func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
|
|
|
|
|
|
|
|
// FROM: http://golang.org/src/net/http/transport.go
|
|
|
|
var portMap = map[string]string{
|
|
|
|
"http": "80",
|
|
|
|
"https": "443",
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:14:07 +00:00
|
|
|
// canonicalAddr returns url.Host but always with a ":port" suffix
|
2016-09-01 21:46:31 +00:00
|
|
|
// FROM: http://golang.org/src/net/http/transport.go
|
2016-09-19 21:14:07 +00:00
|
|
|
func canonicalAddr(url *url.URL) string {
|
2016-09-01 21:46:31 +00:00
|
|
|
addr := url.Host
|
|
|
|
if !hasPort(addr) {
|
|
|
|
return addr + ":" + portMap[url.Scheme]
|
|
|
|
}
|
|
|
|
return addr
|
|
|
|
}
|