File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,17 @@ const requestCache = [
48
48
'only-if-cached'
49
49
]
50
50
51
+ // https://fetch.spec.whatwg.org/#request-body-header-name
51
52
const requestBodyHeader = [
52
53
'content-encoding' ,
53
54
'content-language' ,
54
55
'content-location' ,
55
- 'content-type'
56
+ 'content-type' ,
57
+ // See https://github.com/nodejs/undici/issues/2021
58
+ // 'Content-Length' is a forbidden header name, which is typically
59
+ // removed in the Headers implementation. However, undici doesn't
60
+ // filter out headers, so we add it here.
61
+ 'content-length'
56
62
]
57
63
58
64
// https://fetch.spec.whatwg.org/#enumdef-requestduplex
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const { test } = require ( 'tap' )
4
+ const { once } = require ( 'events' )
5
+ const { createServer } = require ( 'http' )
6
+ const { fetch } = require ( '../..' )
7
+
8
+ // https://github.com/nodejs/undici/issues/2021
9
+ test ( 'content-length header is removed on redirect' , async ( t ) => {
10
+ const server = createServer ( ( req , res ) => {
11
+ if ( req . url === '/redirect' ) {
12
+ res . writeHead ( 302 , { Location : '/redirect2' } )
13
+ res . end ( )
14
+ return
15
+ }
16
+
17
+ res . end ( )
18
+ } ) . listen ( 0 ) . unref ( )
19
+
20
+ t . teardown ( server . close . bind ( server ) )
21
+ await once ( server , 'listening' )
22
+
23
+ const body = 'a+b+c'
24
+
25
+ await t . resolves ( fetch ( `http://localhost:${ server . address ( ) . port } /redirect` , {
26
+ method : 'POST' ,
27
+ body,
28
+ headers : {
29
+ 'content-length' : Buffer . byteLength ( body )
30
+ }
31
+ } ) )
32
+ } )
You can’t perform that action at this time.
0 commit comments