-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
feat: Implement getHeader and appendHeader methods in adapters #12955
Conversation
The setHeader method would replace a header, while there can be multiple headers with the same name
Pull Request Test Coverage Report for Build a19f3222-a87f-49bf-bae3-68d04524a30c
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks like a simple enough change. Would be great to see a test in the integration suite to show this is working as intended, but otherwise I'm good with this
I don't have too much free time to write the tests for now, but I'll look into it as soon as possible. |
Out of curiosity, is there any specific reason we need this at the framework level? I'm assuming you know what platform you're going to use for your project, and framework internals dont use these methods (at least so far) |
I believe the aim of NestJS is to be as much modular as possible. Yes, you do know which framework you're going to use on your project, but what if you change it to fastify? The method names for Fastify Client aren't the same as Express' ones. So I ended up with adding these methods, so you can create an abstract response object and use it as you wish. |
But I believe it isn't going to be merged. I won't write the tests because I don't have enough free time, but feel free to write it, so it can be merged. It would be very useful for many people, I bet |
The setHeader method would replace a header, while there can be multiple headers with the same name
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Talking about cookie headers, you can have more than one header with the same key (two Set-Cookie headers). With the existing setHeader method, a header in Express could not be appended with the same key, just in Fastify platform, because Fastify handles this problem, unlikely Express.
Issue Number: N/A
What is the new behavior?
I ended up adding a getHeader() and an appendHeader() method. The appendHeader() Express implementation calls
response.append(name, value)
, and the Fastify implementation calls `response.header(name, value). Now, you can have more than one Set-Cookie header in Express.Does this PR introduce a breaking change?