Skip to content
Merged
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
5 changes: 4 additions & 1 deletion lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,10 @@ function writeH2 (client, request) {
const expectsPayload = (
method === 'PUT' ||
method === 'POST' ||
method === 'PATCH'
method === 'PATCH' ||
method === 'QUERY' ||
method === 'PROPFIND' ||
method === 'PROPPATCH'
)

if (body && typeof body.read === 'function') {
Expand Down
44 changes: 44 additions & 0 deletions test/http2-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,50 @@ test('Should handle h2 request without body', async t => {
await t.completed
})

test('Should send content-length: 0 for empty h2 requests with payload-expecting methods', async t => {
const assert = tspl(t, { plan: 18 })
const methods = ['PUT', 'POST', 'PATCH', 'QUERY', 'PROPFIND', 'PROPPATCH']

const server = createSecureServer(await pem.generate({ opts: { keySize: 2048 } }))

server.on('stream', (stream, headers) => {
assert.strictEqual(headers['content-length'], '0')
assert.ok(methods.includes(headers[':method']))

stream.respond({ ':status': 200 })
stream.end('ok')
})

await once(server.listen(0), 'listening')

const client = new Client(`https://localhost:${server.address().port}`, {
connect: {
rejectUnauthorized: false
},
allowH2: true
})

t.after(async () => {
server.close()
await client.close()
})

for (const method of methods) {
const response = await client.request({
path: '/',
method,
body: ''
})

assert.strictEqual(response.statusCode, 200)

response.body.resume()
await once(response.body, 'end')
}

await assert.completed
})

test('Should handle h2 request with body (string or buffer) - dispatch', async t => {
t = tspl(t, { plan: 7 })

Expand Down
Loading