question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

res object seems to be missing setHeader()

See original GitHub issue

This looks like an excellent solution for a low bandwidth web serving using functions - eg static pages for a SPA.

however I’m getting an error using your example in the finalhandler module used by express. It appears your mock response object is missing setHeader()

express: 2.5.11 finalhandler: 0.5.0

https://github.com/pillarjs/finalhandler/blob/master/index.js#L202

Perhaps the issues is your code is written for a specific version of express and they’re been breaking changes since?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveALeecommented, Feb 2, 2017

@ejferg

Thanks for the fix. I spent quite a bit of time with the Express code and didn’t spot  x-powered-by could be disabled. The reason that header is send is not so explicit in the code and I’m not an express user.

I think I used express 2.x as your example had and I wasn’t sure if newer version might have broken you mocking of the HTTP objects. I will certainly try it sometime.

I totally agree it’s a great approach for an API serving JSON payloads. I wanted a solution for that and serving my static objects (index.html etc). Seems in that case I got a bit carried away 😃

I might revisit it sometime. It seemed to me that Functions only support strings for buffers (ie in memory copies) rather than streaming from files. That’s fine for dev but not for production.

Thanks again for getting back to me.

1reaction
yvelecommented, Jan 31, 2017

@ejferg @SteveALee Hi thanks for reporting the issue… I’ll have a look quite soon 😉

PS: Feel free to make a PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Can't set headers after they are sent to the client
The res object in Express is a subclass of Node.js's http.ServerResponse (read the http.js source). You are allowed to call res.setHeader(name, value) as ......
Read more >
Unable to set header in server.ext() #2307 - hapijs/hapi - GitHub
But I'm looking to have it set conditionally in the .ext() function. From the docs it looks like I should be able to...
Read more >
apex - API Header authorization for Bright Pattern
It looks like there is an Problem with the opening bracket after the request.setHeader . However, it looks okay to me. Http http...
Read more >
Using HttpRequest Object How To Set Header & Body Elements
I presume I should set the header ServiceAuthHeader elements using req.setHeader(). Thanks in advance for your help. April 6, 2011 ...
Read more >
API Reference - Express 4.x
A new body object containing the parsed data is populated on the request object ... res.set() after res.append() will reset the previously-set header...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found