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: HTTP/2 server cannot accept HTTP requests #19755

Closed
rakyll opened this issue Mar 29, 2017 · 2 comments
Closed

net/http: HTTP/2 server cannot accept HTTP requests #19755

rakyll opened this issue Mar 29, 2017 · 2 comments
Milestone

Comments

@rakyll
Copy link
Contributor

rakyll commented Mar 29, 2017

$ go version
go version devel +54af18708b Wed Mar 29 00:02:06 2017 +0000 darwin/amd64

Consider the following server:

package main

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

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		io.WriteString(w, "hello")
	})
	log.Fatal(http.ListenAndServeTLS("localhost:4444", "server.crt", "server.key", nil))
}

Requests to the server via HTTP is broken and the server logs the following error message:

2017/03/28 17:45:36 http: TLS handshake error from 127.0.0.1:51664: tls: first record does not look like a TLS handshake
curl -v http://localhost:4444
* Rebuilt URL to: http://localhost:4444/
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 4444 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.51.0
> Accept: */*
>

* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact

/cc @tombergan @bradfitz

@rakyll rakyll added this to the Go1.9 milestone Mar 29, 2017
@rakyll rakyll changed the title net/http: HTTP/2 server cannot accept HTTP requests locally net/http: HTTP/2 server cannot accept HTTP requests Mar 29, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Mar 29, 2017

Not a bug. Working as intended.

You're expecting the same port to conditionally do either TLS+http2 vs plaintext http1 depending on what the client sends first?

Typically HTTP is on port 80 and HTTP/2 is on 443 (standard TLS port).

Does any other server mux on the client's first few bytes, distinguishing between an HTTP/1 verb vs. a TLS ClientHello record? (or whatever it starts with)

@rakyll
Copy link
Contributor Author

rakyll commented Mar 29, 2017

Ah, sorry. Starting a TLS server and expecting it to downgrade to HTTP is stupid.

@rakyll rakyll closed this as completed Mar 29, 2017
@golang golang locked and limited conversation to collaborators Mar 29, 2018
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