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

fix: request set headers #2817

Merged
merged 11 commits into from Aug 9, 2021
Merged

fix: request set headers #2817

merged 11 commits into from Aug 9, 2021

Conversation

Eomm
Copy link
Member

@Eomm Eomm commented Jan 24, 2021

Fix #2813

The use case is:
some validation framework returns an object as results of the validation { value: <validated object with defaults> }.
In this case, we must set that object as the request.headers value.

Before #2426 we had a private headers property that was customized and it was acting like a mirror of the raw.headers object.
Now, with this PR, it becomes possible to manage the HTTPIncompingRequest's headers, so, for example, the onRequest hooks will read headers that could be totally different in the preHandler hooks because of the validation process.

What do you think?

(In any case, this PR needs more tests)

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to not alter req.raw.headers. An alternative implementation is to redefine the headers property on request in the setter, bypassing the getter and use a newly stored value.

lib/request.js Outdated Show resolved Hide resolved
lib/request.js Outdated Show resolved Hide resolved
@mcollina
Copy link
Member

looks good so far

Base automatically changed from master to main March 26, 2021 12:02
@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue or pr with more than 15 days of inactivity. label Jun 26, 2021
@stale stale bot removed the stale Issue or pr with more than 15 days of inactivity. label Jun 26, 2021
@mcollina
Copy link
Member

mcollina commented Aug 3, 2021

@Eomm are you still pursuiing this?

@Eomm
Copy link
Member Author

Eomm commented Aug 5, 2021

@Eomm are you still pursuiing this?

Yes, I implemented the I prefer to not alter req.raw.headers. change requested, keeping the headers separated and trying to do not impact normal flow.

@Eomm Eomm marked this pull request as ready for review August 5, 2021 08:13
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor spelling comment. Otherwise lgtm

docs/Request.md Outdated Show resolved Hide resolved
docs/Request.md Outdated Show resolved Hide resolved
Co-authored-by: Vincent LE GOFF <vince.legoff@gmail.com>
Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

lib/request.js Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit fb5e1f1 into fastify:main Aug 9, 2021
@jonnyynnoj jonnyynnoj mentioned this pull request Sep 5, 2021
4 tasks
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2022
@Eomm Eomm deleted the fix-joi-validation branch August 10, 2022 07:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation tries to set headers but its not possible
4 participants