3
3
* request.js
4
4
*
5
5
* Request class contains server only options
6
+ *
7
+ * All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
6
8
*/
7
9
8
10
import Headers from './headers.js' ;
@@ -151,7 +153,7 @@ export function getNodeRequestOptions(request) {
151
153
const parsedURL = request [ INTERNALS ] . parsedURL ;
152
154
const headers = new Headers ( request [ INTERNALS ] . headers ) ;
153
155
154
- // fetch step 3
156
+ // fetch step 1. 3
155
157
if ( ! headers . has ( 'Accept' ) ) {
156
158
headers . set ( 'Accept' , '*/*' ) ;
157
159
}
@@ -165,7 +167,7 @@ export function getNodeRequestOptions(request) {
165
167
throw new TypeError ( 'Only HTTP(S) protocols are supported' ) ;
166
168
}
167
169
168
- // HTTP-network-or-cache fetch steps 5-9
170
+ // HTTP-network-or-cache fetch steps 2.4-2.7
169
171
let contentLengthValue = null ;
170
172
if ( request . body == null && / ^ ( P O S T | P U T ) $ / i. test ( request . method ) ) {
171
173
contentLengthValue = '0' ;
@@ -180,20 +182,20 @@ export function getNodeRequestOptions(request) {
180
182
headers . set ( 'Content-Length' , contentLengthValue ) ;
181
183
}
182
184
183
- // HTTP-network-or-cache fetch step 12
185
+ // HTTP-network-or-cache fetch step 2.11
184
186
if ( ! headers . has ( 'User-Agent' ) ) {
185
187
headers . set ( 'User-Agent' , 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' ) ;
186
188
}
187
189
188
- // HTTP-network-or-cache fetch step 16
190
+ // HTTP-network-or-cache fetch step 2.15
189
191
if ( request . compress ) {
190
192
headers . set ( 'Accept-Encoding' , 'gzip,deflate' ) ;
191
193
}
192
194
if ( ! headers . has ( 'Connection' ) && ! request . agent ) {
193
195
headers . set ( 'Connection' , 'close' ) ;
194
196
}
195
197
196
- // HTTP-network fetch step 4
198
+ // HTTP-network fetch step 4.2
197
199
// chunked encoding is handled by Node.js
198
200
199
201
return Object . assign ( { } , parsedURL , {
0 commit comments