Skip to content

Commit

Permalink
fix: retry idempotent with original body
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 2, 2020
1 parent 52deded commit d93d222
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,6 @@ function write (client, request) {
if (!expectsPayload) {
client[kReset] = true
}

request.body = null
} else {
client[kWriting] = true

Expand Down
43 changes: 43 additions & 0 deletions test/client-idempotent-body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

const { test } = require('tap')
const { Client } = require('..')
const { createServer } = require('http')

test('idempotent retry', (t) => {
t.plan(11)

const body = 'world'
const server = createServer((req, res) => {
let buf = ''
req.on('data', data => {
buf += data
}).on('end', () => {
t.strictDeepEqual(buf, body)
res.end()
})
})
t.tearDown(server.close.bind(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
pipelining: 2
})
t.tearDown(client.close.bind(client))

const _err = new Error()

for (let n = 0; n < 4; ++n) {
client.stream({
path: '/',
method: 'PUT',
idempotent: true,
body
}, () => {
throw _err
}, (err) => {
t.strictEqual(err, _err)
})
}
})
})

0 comments on commit d93d222

Please sign in to comment.