Skip to content

Commit

Permalink
test content-length in request is undefined or 0
Browse files Browse the repository at this point in the history
  • Loading branch information
pxue committed Oct 15, 2023
1 parent 194a60c commit 741b811
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions test/content-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,13 @@ test('request streaming with Readable.from(buf)', (t) => {
})

test('request DELETE, content-length=0, with body', (t) => {
t.plan(4)
t.plan(5)
const server = createServer((req, res) => {
res.end()
})
server.on('request', (req, res) => {
t.equal(req.headers['content-length'], undefined)
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
Expand Down Expand Up @@ -333,17 +336,30 @@ test('request DELETE, content-length=0, with body', (t) => {
})

test('content-length shouldSendContentLength=false', (t) => {
t.plan(12)
t.plan(15)
const server = createServer((req, res) => {
res.end()
})
server.on('request', (req, res) => {
switch (req.url) {
case '/put0':
t.equal(req.headers['content-length'], '0')
break
case '/head':
t.equal(req.headers['content-length'], undefined)
break
case '/get':
t.equal(req.headers['content-length'], undefined)
break
}
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.teardown(client.destroy.bind(client))

client.request({
path: '/',
path: '/put0',
method: 'PUT',
headers: {
'content-length': 0
Expand All @@ -354,7 +370,7 @@ test('content-length shouldSendContentLength=false', (t) => {
})

client.request({
path: '/',
path: '/head',
method: 'HEAD',
headers: {
'content-length': 10
Expand All @@ -365,7 +381,7 @@ test('content-length shouldSendContentLength=false', (t) => {
})

client.request({
path: '/',
path: '/get',
method: 'GET',
headers: {
'content-length': 0
Expand Down

0 comments on commit 741b811

Please sign in to comment.