Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ Object.defineProperty(requestPrototype, 'signal', {
'cache',
'credentials',
'destination',
'duplex',
'integrity',
'mode',
'redirect',
Expand Down
32 changes: 32 additions & 0 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('Request', () => {
expect(req.url).toBe('http://localhost/')
expect(req.headers.get('host')).toBe('localhost')
expect(req.keepalive).toBe(false)
expect(req.duplex).toBe('half')
})

it('Should not generate GlobalRequest when accessing method, url or headers', async () => {
Expand Down Expand Up @@ -1170,6 +1171,37 @@ describe('Request', () => {
expect(req2).toBeInstanceOf(GlobalRequest)
await expect(req2.text()).resolves.toBe('bar')
})

it('should be success to create instance with a lightweight GET request as init option', () => {
const req = newRequest({
method: 'GET',
url: '/',
headers: {
host: 'localhost',
},
rawHeaders: ['host', 'localhost'],
} as IncomingMessage)
const req2 = new Request('http://localhost/subapp', req)
expect(req2).toBeInstanceOf(GlobalRequest)
expect(req2.method).toBe('GET')
expect(req2.url).toBe('http://localhost/subapp')
})

it('should be success to create instance with a lightweight POST request as init option', async () => {
const req = newRequest({
method: 'POST',
url: '/',
headers: {
host: 'localhost',
},
rawHeaders: ['host', 'localhost'],
rawBody: Buffer.from('foo'),
} as IncomingMessage & { rawBody: Buffer })
const req2 = new Request('http://localhost/subapp', req)
expect(req2).toBeInstanceOf(GlobalRequest)
expect(req2.method).toBe('POST')
await expect(req2.text()).resolves.toBe('foo')
})
})
})

Expand Down
Loading