Skip to content

Commit

Permalink
fix(koa): restore writeHead once we're done
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Jun 22, 2018
1 parent e3bf765 commit 50be982
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/postgraphile/http/createPostGraphileHttpRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,17 @@ export default function createPostGraphileHttpRequestHandler(options) {

// Hack the req object so we can get back to ctx
ctx.req._koaCtx = ctx

const oldWriteHead = ctx.res.writeHead
ctx.res.writeHead = () => {
throw new Error('res.writeHead not supported in Koa environment')
}

const oldSend = ctx.res.send
ctx.res.send = () => {
throw new Error('res.send not supported in Koa environment')
}

const oldEnd = ctx.res.end
ctx.res.end = (body) => {
ctx.response.body = body
Expand All @@ -786,6 +791,8 @@ export default function createPostGraphileHttpRequestHandler(options) {
try {
result = await requestHandler(ctx.req, ctx.res, next)
} finally {
ctx.res.writeHead = oldWriteHead
ctx.res.send = oldSend
ctx.res.end = oldEnd
if (ctx.res.statusCode && ctx.res.statusCode !== 200) {
ctx.response.status = ctx.res.statusCode
Expand Down

0 comments on commit 50be982

Please sign in to comment.