|
@@ -77,6 +77,10 @@ type Transport struct {
|
|
|
// uncompressed.
|
|
// uncompressed.
|
|
|
DisableCompression bool
|
|
DisableCompression bool
|
|
|
|
|
|
|
|
|
|
+ // AllowHTTP, if true, permits HTTP/2 requests using the insecure,
|
|
|
|
|
+ // plain-text "http" scheme. Note that this does not enable h2c support.
|
|
|
|
|
+ AllowHTTP bool
|
|
|
|
|
+
|
|
|
// MaxHeaderListSize is the http2 SETTINGS_MAX_HEADER_LIST_SIZE to
|
|
// MaxHeaderListSize is the http2 SETTINGS_MAX_HEADER_LIST_SIZE to
|
|
|
// send in the initial settings frame. It is how many bytes
|
|
// send in the initial settings frame. It is how many bytes
|
|
|
// of response headers are allow. Unlike the http2 spec, zero here
|
|
// of response headers are allow. Unlike the http2 spec, zero here
|
|
@@ -275,20 +279,24 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
|
|
|
|
|
|
// authorityAddr returns a given authority (a host/IP, or host:port / ip:port)
|
|
// authorityAddr returns a given authority (a host/IP, or host:port / ip:port)
|
|
|
// and returns a host:port. The port 443 is added if needed.
|
|
// and returns a host:port. The port 443 is added if needed.
|
|
|
-func authorityAddr(authority string) (addr string) {
|
|
|
|
|
|
|
+func authorityAddr(scheme string, authority string) (addr string) {
|
|
|
if _, _, err := net.SplitHostPort(authority); err == nil {
|
|
if _, _, err := net.SplitHostPort(authority); err == nil {
|
|
|
return authority
|
|
return authority
|
|
|
}
|
|
}
|
|
|
- return net.JoinHostPort(authority, "443")
|
|
|
|
|
|
|
+ port := "443"
|
|
|
|
|
+ if scheme == "http" {
|
|
|
|
|
+ port = "80"
|
|
|
|
|
+ }
|
|
|
|
|
+ return net.JoinHostPort(authority, port)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// RoundTripOpt is like RoundTrip, but takes options.
|
|
// RoundTripOpt is like RoundTrip, but takes options.
|
|
|
func (t *Transport) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Response, error) {
|
|
func (t *Transport) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Response, error) {
|
|
|
- if req.URL.Scheme != "https" {
|
|
|
|
|
|
|
+ if !(req.URL.Scheme == "https" || (req.URL.Scheme == "http" && t.AllowHTTP)) {
|
|
|
return nil, errors.New("http2: unsupported scheme")
|
|
return nil, errors.New("http2: unsupported scheme")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- addr := authorityAddr(req.URL.Host)
|
|
|
|
|
|
|
+ addr := authorityAddr(req.URL.Scheme, req.URL.Host)
|
|
|
for {
|
|
for {
|
|
|
cc, err := t.connPool().GetClientConn(req, addr)
|
|
cc, err := t.connPool().GetClientConn(req, addr)
|
|
|
if err != nil {
|
|
if err != nil {
|