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

feat: Implement getHeader and appendHeader methods in adapters #12955

Merged
merged 4 commits into from
Feb 7, 2024

Conversation

josesilveiraa07
Copy link
Contributor

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?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

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?

  • Yes
  • No

@Tony133
Copy link
Contributor

Tony133 commented Dec 20, 2023

Tests fail, here:

test-fail

@josesilveiraa07
Copy link
Contributor Author

Failure to test here:
test-fail

My bad, missed this one. Anyway, fixed in the latest commit

@coveralls
Copy link

Pull Request Test Coverage Report for Build a19f3222-a87f-49bf-bae3-68d04524a30c

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.1%

Totals Coverage Status
Change from base Build 7ac098a9-c60b-4faa-9612-e3dbed2e2eb6: 0.0%
Covered Lines: 6715
Relevant Lines: 7291

💛 - Coveralls

Copy link
Member

@jmcdo29 jmcdo29 left a 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

@josesilveiraa07
Copy link
Contributor Author

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.

@kamilmysliwiec
Copy link
Member

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)

@josesilveiraa07
Copy link
Contributor Author

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.

@josesilveiraa07
Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

8 participants