File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,6 @@ function Response(req) {
33
33
this . request = req ;
34
34
this . req = req . req ;
35
35
this . text = res . text ;
36
- this . body = res . body === undefined ? { } : res . body ;
37
36
this . files = res . files || { } ;
38
37
this . buffered = req . _resBuffered ;
39
38
this . headers = res . headers ;
@@ -47,6 +46,21 @@ function Response(req) {
47
46
res . on ( 'error' , this . emit . bind ( this , 'error' ) ) ;
48
47
}
49
48
49
+ // Lazy access res.body.
50
+ // https://github.com/nodejs/node/pull/39520#issuecomment-889697136
51
+ Object . defineProperty ( Response . prototype , 'body' , {
52
+ get ( ) {
53
+ return this . _body !== undefined
54
+ ? this . _body
55
+ : this . res . body !== undefined
56
+ ? this . res . body
57
+ : { } ;
58
+ } ,
59
+ set ( value ) {
60
+ this . _body = value ;
61
+ }
62
+ } ) ;
63
+
50
64
/**
51
65
* Inherit from `Stream`.
52
66
*/
You can’t perform that action at this time.
0 commit comments