Skip to content

Commit 33f72b4

Browse files
authored
Return 413 when request too large (#41)
1 parent fbd87da commit 33f72b4

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to
77
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [v1.0.0-beta.16]
10+
11+
- Return `413` status code instead of `500` when RPC request body exceeds size limit
12+
913
## [v1.0.0-beta.15]
1014

1115
- Reduce noisy logs

node/immutable_newrelic.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package node
1919
import (
2020
"bytes"
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"io"
2425
"net/http"
@@ -63,6 +64,12 @@ func newRelicMiddleware(nrApp *newrelic.Application, next http.Handler) http.Han
6364
mb := int64(1024 * 1024)
6465
body, bodyReader, err := limitedTeeRead(req.Body, mb)
6566
if err != nil {
67+
if errors.Is(err, errBodySizeExceedsLimit) {
68+
log.Warn(err.Error())
69+
http.Error(w, http.StatusText(http.StatusRequestEntityTooLarge), http.StatusRequestEntityTooLarge)
70+
return
71+
}
72+
6673
log.WithError(err).Error("Failed to read request body")
6774
// respond to the client with a 503 error.
6875
// We want to respond here because we can't use the body in subsequent handlers anyway.

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
VersionMajor = 1 // Major version component of the current release
2525
VersionMinor = 0 // Minor version component of the current release
2626
VersionPatch = 0 // Patch version component of the current release
27-
VersionMeta = "beta.15" // Version metadata to append to the version string
27+
VersionMeta = "beta.16" // Version metadata to append to the version string
2828
)
2929

3030
// Version holds the textual version string.

0 commit comments

Comments
 (0)