Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed unresponsive server #3283 #3285

Merged
merged 4 commits into from Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reply.js
Expand Up @@ -377,8 +377,8 @@ function preserializeHookEnd (err, request, reply, payload) {
}

function onSendHook (reply, payload) {
reply[kReplySent] = true
if (reply.context.onSend !== null) {
reply[kReplySent] = true
climba03003 marked this conversation as resolved.
Show resolved Hide resolved
onSendHookRunner(
reply.context.onSend,
reply.request,
Expand Down
70 changes: 70 additions & 0 deletions test/reply-error.test.js
Expand Up @@ -525,3 +525,73 @@ test('should trigger error handlers if a sync route throws any non-error object'
t.equal(reply.statusCode, 500)
t.equal(JSON.parse(reply.body).foo, 'bar')
})

// Issue 3283 https://github.com/fastify/fastify/issues/3283
Krishanu230 marked this conversation as resolved.
Show resolved Hide resolved
test('setting content-type on reply object should not hang the server case 1', t => {
t.plan(2)
const fastify = Fastify()

fastify.get('/', (req, reply) => {
reply
.code(200)
.headers({ 'content-type': 'text/plain; charset=utf-32' })
.send(JSON.stringify({ bar: 'foo', baz: 'foobar' }))
})

fastify.inject({
url: '/',
method: 'GET'
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 200)
})
})

test('setting content-type on reply object should not hang the server case 2', t => {
t.plan(2)
const fastify = Fastify()

fastify.get('/', (req, reply) => {
reply
.code(200)
.headers({ 'content-type': 'text/plain; charset=utf-8' })
.send({ bar: 'foo', baz: 'foobar' })
})

fastify.inject({
url: '/',
method: 'GET'
}, (err, res) => {
// the server should not hang and send a 500 reply
t.error(err)
t.same(
{
error: 'Internal Server Error',
message: 'Attempted to send payload of invalid type \'object\'. Expected a string or Buffer.',
statusCode: 500,
code: 'FST_ERR_REP_INVALID_PAYLOAD_TYPE'
},
JSON.parse(res.payload)
)
})
})
Krishanu230 marked this conversation as resolved.
Show resolved Hide resolved

test('setting content-type on reply object should not hang the server case 3', t => {
t.plan(2)
const fastify = Fastify()

fastify.get('/', (req, reply) => {
reply
.code(200)
.headers({ 'content-type': 'application/json' })
.send({ bar: 'foo', baz: 'foobar' })
})

fastify.inject({
url: '/',
method: 'GET'
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 200)
})
})