Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: http2 client return EOF #13598

Closed
mattn opened this issue Dec 13, 2015 · 4 comments
Closed

net/http: http2 client return EOF #13598

mattn opened this issue Dec 13, 2015 · 4 comments
Milestone

Comments

@mattn
Copy link
Member

mattn commented Dec 13, 2015

I'm trying to connect to https://dav.box.com/ with golang. It seems that box.com provide http2 protocol. But go's http2 client retrun EOF always. I debugged little and I make sure this occur on h2 protocol in TLSNextProto. So currently I'm disabling h2 like below.

http.DefaultTransport.(*http.Transport).TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper)
@mattn
Copy link
Member Author

mattn commented Dec 13, 2015

/cc @bradfitz

@bradfitz bradfitz self-assigned this Dec 13, 2015
@bradfitz bradfitz added this to the Go1.6 milestone Dec 13, 2015
@bradfitz bradfitz changed the title http2 client return EOF net/http: http2 client return EOF Dec 13, 2015
@bradfitz
Copy link
Contributor

Indeed! Thanks for the bug report.

brad5k:~ $ cat get.go
package main

import (
    "io"
    "log"
    "net/http"
    "os"
)

func main() {
    res, err := http.Get("https://dav.box.com/")
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Res: %#v", res)
    _, err = io.Copy(os.Stdout, res.Body)
    if err != nil {
        log.Fatal(err)
    }
}

With HTTP/2 enabled by default: (mix of error messages)

brad5k:~ $ go run get.go 
2015/12/13 11:19:14 Get https://dav.box.com/: EOF
exit status 1
brad5k:~ $ go run get.go 
2015/12/13 11:19:15 Get https://dav.box.com/: EOF
exit status 1
brad5k:~ $ go run get.go 
2015/12/13 11:19:17 Get https://dav.box.com/: read tcp 10.0.0.55:55327->74.112.184.85:443: read: connection reset by peer
exit status 1

With HTTP/2 explicitly disabled:

brad5k:~ $ GODEBUG=h2client=0 go run get.go
2015/12/13 11:18:13 Res: &http.Response{Status:"401 Unauthorized", StatusCode:401, Proto:"HTTP/1.1", ProtoMajor:1, ProtoMinor:1, Header:http.Header{"Content-Length":[]string{"242"}, "Date":[]string{"Sun, 13 Dec 2015 19:18:13 GMT"}, "Age":[]string{"0"}, "Connection":[]string{"keep-alive"}, "Server":[]string{"ATS"}, "Content-Type":[]string{"application/xml; charset=utf-8"}, "Www-Authenticate":[]string{"Basic realm=\"dav.box.com\""}}, Body:(*http.bodyEOFSignal)(0xc8201380c0), ContentLength:242, TransferEncoding:[]string(nil), Close:false, Trailer:http.Header(nil), Request:(*http.Request)(0xc8200ce000), TLS:(*tls.ConnectionState)(0xc82035f080)}
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre_DAV_Exception_NotAuthenticated</s:exception>
  <s:message>No basic authentication headers were found</s:message>
</d:error>

@mattn
Copy link
Member Author

mattn commented Dec 14, 2015

Yes, I got same result.

@bradfitz
Copy link
Contributor

I found the problem. https://dav.box.com does not speak HTTP/2. But we advertise in our TLS connection that we speak "h2" but we never mention that we also speak "http/1.1", and Box's frontend recognizes ALPN or NPN enough to know that they can't handle "h2", so they hang up on us.

The fix is to declare that we also speak "http/1.1" as a fallback.

Easy fix.

bradfitz added a commit to golang/net that referenced this issue Dec 14, 2015
RFC 7301 defines the ALPN protocol "http/1.1".

We weren't sending that, so at least one site (dav.box.com) was
rejecting our connection, since they didn't support the only protocol
we advertised ("h2").  Had we advertised nothing, they would've
assumed http/1.1 implicitly.

This CL also hooks up the verbose logging knob to the GODEBUG
environment variable.

Updates golang/go#13598 (fixed when this is copied into std)

Change-Id: I6ea1231d0d0f0bc767caa0458237eefd943d9d3d
Reviewed-on: https://go-review.googlesource.com/17754
Reviewed-by: Ian Lance Taylor <iant@golang.org>
mattn added a commit to mattn/davc that referenced this issue Dec 15, 2015
@golang golang locked and limited conversation to collaborators Dec 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants