@@ -48,6 +48,8 @@ func (ls *LivepeerServer) StartStream() http.Handler {
48
48
return
49
49
}
50
50
51
+ //setup body size limit, will error if too large
52
+ r .Body = http .MaxBytesReader (w , r .Body , 10 << 20 )
51
53
streamUrls , code , err := ls .setupStream (ctx , r , gatewayJob )
52
54
if err != nil {
53
55
clog .Errorf (ctx , "Error setting up stream: %s" , err )
@@ -383,9 +385,15 @@ func (ls *LivepeerServer) setupStream(ctx context.Context, r *http.Request, job
383
385
384
386
// Setup request body to be able to preserve for retries
385
387
// 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 )
387
389
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
+ }
389
397
}
390
398
r .Body .Close ()
391
399
0 commit comments