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: wrong/undocumented response behaviors when unsupported HTTP version is used #40454

Closed
urbanishimwe opened this issue Jul 28, 2020 · 7 comments

Comments

@urbanishimwe
Copy link

@urbanishimwe urbanishimwe commented Jul 28, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.6 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

created a server with the most minimal configurations

package main

import (
        "fmt"
        "net/http"
)

func main() {
        if err := http.ListenAndServe(":8001", http.HandlerFunc(handler)); err != nil {
                fmt.Println(err)
        }
}

func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "")
}

made a TCP request

printf "GET / HTTP/2.0\r\nHOST: 127.0.0.1:80\r\n\r\n" | nc 127.0.0.1 8001

What did you expect to see?

as in https://tools.ietf.org/html/rfc7231#section-6.6.6

505 HTTP Version Not Supported\r\n...

What did you see instead?

HTTP/1.1 400 Bad Request: unsupported protocol version\r\nContent-Type: text/plain; charset=utf-8\r\nConnection: close\r\n\r\n400 Bad Request: unsupported protocol version

I think the server should also indicate the body length if there is any.

@networkimprov
Copy link

@networkimprov networkimprov commented Jul 28, 2020

@gopherbot remove Documentation

@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Jul 29, 2020

@bcmills
Copy link
Member

@bcmills bcmills commented Jul 31, 2020

Please provide the steps to reproduce as a Go program, not (just) a Unix command-line. (How did you configure the server on the Go side?)

@urbanishimwe
Copy link
Author

@urbanishimwe urbanishimwe commented Jul 31, 2020

(How did you configure the server on the Go side?)

Basic configurations like this can reproduce the issue

package main

import (
        "fmt"
        "net/http"
)

func main() {
        if err := http.ListenAndServe(":8001", http.HandlerFunc(handler)); err != nil {
                fmt.Println(err)
        }
}

func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "")
}
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Oct 6, 2020

I'd never heard of 505. Seems fine.

/cc @neild

@urbanishimwe
Copy link
Author

@urbanishimwe urbanishimwe commented Oct 7, 2020

I think the ": unsupported protocol version" after "400 Bad Request" shouldn't be there.
since the response has body, it could be nice to provide Content-Length header for easy parsing(?)

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 13, 2020

Change https://golang.org/cl/261977 mentions this issue: net/http: return 505 status for rejected protocol version

@gopherbot gopherbot closed this in 9c56300 Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants