hapi icon indicating copy to clipboard operation
hapi copied to clipboard

Failed to get `request.response` object from 'response' event

Open chunfengd opened this issue 8 years ago • 4 comments

Is this a security related issue?

No

What are you trying to achieve or the steps to reproduce?

When I listen on the response event, the request.response is always null. This happens in version 17.5.4, but not in 17.5.2.

const server = Hapi.server({
  port: 8080,
});

server.route({
  method: 'GET',
  path: '/echo',
  handler: request => {
    return Object.keys(request);
  },
});

server.events.on('response', request => {
  console.log(
    request.info.remoteAddress +
      ': ' +
      request.method.toUpperCase() +
      ' ' +
      request.url.path +
      ' --> ' +
      (request.response && request.response.statusCode) // request.response is always null
  );
  if (request.response && request.response._error) {
    console.log(request.response._error);
  }
});

server.start()

What was the result you received?

request.response is always null

What did you expect?

I expect to get the response object from the event callback

Context

  • node version:10.6.0
  • hapi version: 17.5.4
  • os: alpine (I run the code in a node:alpine docker container)
  • any other relevant information:

chunfengd avatar Sep 21 '18 15:09 chunfengd

Cannot reproduce.

hueniverse avatar Sep 23 '18 07:09 hueniverse

We have been running into the same issue. We are using hapi version: 17.6. We noticed that it had something to do with the version of node we were using. We were running node version: 10.2.1. We also noted an issue running node version: 10.6.0.

Not sure what the root cause is, but we reported success with node version 8.12.0 and 10.10.0.

Aex avatar Oct 08 '18 18:10 Aex

@Aex confirmed, was having issues on node 11.3.0.

Switched to 10.10.0 and it worked.

kminehart avatar Dec 06 '18 22:12 kminehart

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

lock[bot] avatar Jan 09 '20 11:01 lock[bot]