Skip to content

net/http: ErrBodyReadAfterClose text error message should be relevant for response as well #3997

Closed
@gopherbot

Description

@gopherbot

by elazarl:

1. Create a new response
2. Write the response twice
3. The error you'll receive is, "http: invalid Read on closed request Body",
which is confusing, s/request/request or response/.

For example http://play.golang.org/p/tBwXSkWhMG

func main() {
    req, _ := http.NewRequest("GET",
        "http://google.com";, strings.NewReader(""))
    resp, _ := http.ReadResponse(
        bufio.NewReader(strings.NewReader(
        "HTTP/1.1 200 OK\r\n"+
        "Content-Type: text/plain\r\n"+
        "Content-Length: 1\r\n\r\na")), req)
    resp.Write(ioutil.Discard)
    fmt.Println(resp.Write(ioutil.Discard))
}

 [1] http://tip.golang.org/src/pkg/net/http/transfer.go#L528

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions