Skip to content
Closed
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
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ function getResponseStatusCode (res) {

function send (req, res, status, headers, message) {
function write () {
if (res.headersSent) {
return
}

// response body
var body = createHtmlDocument(message)

Expand Down
28 changes: 28 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,34 @@ var topDescribe = function (type, createServer) {
test.write(buf)
test.expect(500, done)
})

it('should not throw if headers are sent while waiting for request', function (done) {
var buf = Buffer.alloc(1024 * 16, '.')
var server = createServer(function (req, res, next) {
next()
res.setHeader('Content-Type', 'text/plain')
res.end('ok')
})
var test = wrapper(request(server).post('/foo'))
test.write(buf)
test.write(buf)
test.write(buf)
test.expect(200, 'ok', done)
})

it('should not throw if headers are sent while waiting for request on error', function (done) {
var buf = Buffer.alloc(1024 * 16, '.')
var server = createServer(function (req, res, next) {
next(new Error('boom!'))
res.setHeader('Content-Type', 'text/plain')
res.end('error response')
})
var test = wrapper(request(server).post('/foo'))
test.write(buf)
test.write(buf)
test.write(buf)
test.expect(200, 'error response', done)
})
})

describe('when res.statusCode set', function () {
Expand Down