File tree 2 files changed +34
-4
lines changed
2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -260,10 +260,13 @@ function appendRequestOriginHeader (request) {
260
260
// TODO: implement "byte-serializing a request origin"
261
261
let serializedOrigin = request . origin
262
262
263
- // "'client' is changed to an origin during fetching."
264
- // This doesn't happen in undici (in most cases) because undici, by default,
265
- // has no concept of origin.
266
- if ( serializedOrigin === 'client' ) {
263
+ // - "'client' is changed to an origin during fetching."
264
+ // This doesn't happen in undici (in most cases) because undici, by default,
265
+ // has no concept of origin.
266
+ // - request.origin can also be set to request.client.origin (client being
267
+ // an environment settings object), which is undefined without using
268
+ // setGlobalOrigin.
269
+ if ( serializedOrigin === 'client' || serializedOrigin === undefined ) {
267
270
return
268
271
}
269
272
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const { test } = require ( 'node:test' )
4
+ const { tspl } = require ( '@matteo.collina/tspl' )
5
+ const { once } = require ( 'node:events' )
6
+ const { createServer } = require ( 'node:http' )
7
+ const { fetch } = require ( '../..' )
8
+
9
+ test ( 'a non-empty origin is not appended (issue #3334)' , async ( t ) => {
10
+ const { strictEqual } = tspl ( t , { plan : 1 } )
11
+ const origin = 'https://origin.example.com'
12
+
13
+ const server = createServer ( ( req , res ) => {
14
+ strictEqual ( req . headers . origin , origin )
15
+ res . end ( )
16
+ } ) . listen ( 0 )
17
+
18
+ t . after ( server . close . bind ( server ) )
19
+ await once ( server , 'listening' )
20
+
21
+ await fetch ( `http://localhost:${ server . address ( ) . port } ` , {
22
+ headers : { origin } ,
23
+ body : '' ,
24
+ method : 'POST' ,
25
+ redirect : 'error'
26
+ } )
27
+ } )
You can’t perform that action at this time.
0 commit comments