File tree 2 files changed +31
-12
lines changed
2 files changed +31
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @sveltejs/kit ' : patch
3
+ ---
4
+
5
+ Don't automatically buffer request bodies
Original file line number Diff line number Diff line change @@ -18,27 +18,41 @@ function get_raw_body(req) {
18
18
return null ;
19
19
}
20
20
21
+ let size = 0 ;
22
+ let cancelled = false ;
23
+
21
24
return new ReadableStream ( {
22
25
start ( controller ) {
23
26
req . on ( 'error' , ( error ) => {
24
27
controller . error ( error ) ;
25
28
} ) ;
26
29
27
- let size = 0 ;
28
-
29
- req . on ( 'data' , ( chunk ) => {
30
- size += chunk . length ;
31
-
32
- if ( size > length ) {
33
- controller . error ( new Error ( 'content-length exceeded' ) ) ;
30
+ req . on ( 'end' , ( ) => {
31
+ if ( ! cancelled ) {
32
+ controller . close ( ) ;
34
33
}
35
-
36
- controller . enqueue ( chunk ) ;
37
34
} ) ;
38
-
39
- req . on ( 'end' , ( ) => {
40
- controller . close ( ) ;
35
+ } ,
36
+
37
+ pull ( controller ) {
38
+ return new Promise ( ( fulfil ) => {
39
+ req . once ( 'data' , ( chunk ) => {
40
+ if ( ! cancelled ) {
41
+ size += chunk . length ;
42
+ if ( size > length ) {
43
+ controller . error ( new Error ( 'content-length exceeded' ) ) ;
44
+ }
45
+
46
+ controller . enqueue ( chunk ) ;
47
+ }
48
+
49
+ fulfil ( ) ;
50
+ } ) ;
41
51
} ) ;
52
+ } ,
53
+
54
+ cancel ( ) {
55
+ cancelled = true ;
42
56
}
43
57
} ) ;
44
58
}
You can’t perform that action at this time.
0 commit comments