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

make setHeader compatible with fastify reply (patch included) #144

Closed
mariusa opened this issue Dec 29, 2021 · 2 comments
Closed

make setHeader compatible with fastify reply (patch included) #144

mariusa opened this issue Dec 29, 2021 · 2 comments
Labels

Comments

@mariusa
Copy link

mariusa commented Dec 29, 2021

Instead of res.setHeader, fastify uses reply.header("Content-Type", "application/json; charset=utf-8")

http://expressjs.com/en/4x/api.html#res.set
https://www.fastify.io/docs/latest/Reference/Reply/#headerkey-value

Please make setting headers compatible with fastify too.
Instead of this line

var setHeader = res.set ? http.OutgoingMessage.prototype.setHeader : res.setHeader

use

  var setHeader = null
  if (typeof res.set == 'function') {
  	setHeader = http.OutgoingMessage.prototype.setHeader
  } else if (typeof res.setHeader == 'function') {
  	setHeader = res.setHeader
  } else if (typeof res.header == 'function') {
  	//fastify 
  	res.header('Set-Cookie', headers)
  	return this
  }  
  setHeader.call(res, 'Set-Cookie', headers)
  return this
@dougwilson
Copy link
Contributor

Hello, sorry you are having trouble. It seems like you are just passing in the wrong object for Fastify

https://github.com/pillarjs/cookies#new-cookiesrequest-response--options

The request argument is a Node.js HTTP incoming request object and the response argument is a Node.js HTTP server response object.

So for Fastify, this should be cookies = new Cookies(req.raw, reply.raw). I hope this helps!

@mariusa
Copy link
Author

mariusa commented Dec 29, 2021

Thank you, Doug! That helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants