Skip to content

Commit b372b65

Browse files
authored
[#211] from plehatron/request-entity-too-large-response
2 parents b7a3915 + 21a6d38 commit b372b65

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

handler/handler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
137137

138138
req.Close(h.log, r)
139139
h.putReq(req)
140-
http.Error(w, errors.E(op, err).Error(), 500)
140+
status := http.StatusInternalServerError
141+
var maxBytesErr *http.MaxBytesError
142+
if stderr.As(err, &maxBytesErr) {
143+
status = http.StatusRequestEntityTooLarge
144+
}
145+
http.Error(w, errors.E(op, err).Error(), status)
141146
h.log.Error(
142147
"request forming error",
143148
zap.Time("start", start),

tests/http_plugin2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ func TestHTTPBigRespMaxReqSize(t *testing.T) {
605605
}()
606606

607607
assert.NoError(t, err)
608-
assert.Equal(t, 500, r.StatusCode)
608+
assert.Equal(t, http.StatusRequestEntityTooLarge, r.StatusCode)
609609

610610
stopCh <- struct{}{}
611611
wg.Wait()

tests/http_plugin3_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ func TestHTTPBigURLEncoded(t *testing.T) {
11521152
assert.NoError(t, err)
11531153
_, _ = io.ReadAll(resp.Body)
11541154

1155-
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
1155+
require.Equal(t, http.StatusRequestEntityTooLarge, resp.StatusCode)
11561156

11571157
t.Cleanup(func() {
11581158
_ = resp.Body.Close()

tests/http_plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ func TestHTTPBigRequestSize(t *testing.T) {
17861786
assert.NoError(t, err)
17871787
b, err := io.ReadAll(r.Body)
17881788
assert.NoError(t, err)
1789-
assert.Equal(t, 500, r.StatusCode)
1789+
assert.Equal(t, http.StatusRequestEntityTooLarge, r.StatusCode)
17901790
assert.Equal(t, "serve_http: http: request body too large\n", string(b))
17911791

17921792
err = r.Body.Close()

0 commit comments

Comments
 (0)