http.MaxByteReader & http: request body too large

65 views
Skip to first unread message

Jérôme LAFORGE

unread,
Sep 18, 2020, 8:08:12 AM9/18/20
to golang-nuts
Hello,

I want to use http.MaxByteReader, but I want to know if it possible to return an package level error (like context.DeadlineExceeded) instead of create a new one (https://github.com/golang/go/blob/06f7e655d1764f5ad57bc14f82326c181c37901c/src/net/http/request.go#L1158). It seems more goish and it is easiest to test with simple switch case instead of check the content of error (as example below).

Do you think that is compliance with promise of compatibility with Go 1? (I think that it is the case)


func TestMaxBytesReader(t *testing.T) {
req := ioutil.NopCloser(bytes.NewBufferString("my too long request"))
_, err := http.MaxBytesReader(httptest.NewRecorder(), req, 2).Read([]byte{10: 0})
if err == nil || err.Error() != "http: request body too large" {
t.FailNow()
}
}
Reply all
Reply to author
Forward
0 new messages