Skip to content

Commit 67cb9cd

Browse files
add logging end response for too large body
1 parent 18db960 commit 67cb9cd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

server/job_stream.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func (ls *LivepeerServer) StartStream() http.Handler {
4848
return
4949
}
5050

51+
//setup body size limit, will error if too large
52+
r.Body = http.MaxBytesReader(w, r.Body, 10<<20)
5153
streamUrls, code, err := ls.setupStream(ctx, r, gatewayJob)
5254
if err != nil {
5355
clog.Errorf(ctx, "Error setting up stream: %s", err)
@@ -383,9 +385,15 @@ func (ls *LivepeerServer) setupStream(ctx context.Context, r *http.Request, job
383385

384386
// Setup request body to be able to preserve for retries
385387
// Read the entire body first with 10MB limit
386-
bodyBytes, err := io.ReadAll(io.LimitReader(r.Body, 10<<20))
388+
bodyBytes, err := io.ReadAll(r.Body)
387389
if err != nil {
388-
return nil, http.StatusBadRequest, err
390+
if errors.As(err, http.MaxBytesError{}) {
391+
clog.Warningf(ctx, "Request body too large (over 10MB)")
392+
return nil, http.StatusRequestEntityTooLarge, fmt.Errorf("request body too large (max 10MB)")
393+
} else {
394+
clog.Errorf(ctx, "Error reading request body: %v", err)
395+
return nil, http.StatusBadRequest, fmt.Errorf("error reading request body: %w", err)
396+
}
389397
}
390398
r.Body.Close()
391399

0 commit comments

Comments
 (0)