Repository navigation
Conversation
Fixes fastify#269 Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
Member
|
@lx3133584 This is incredibly similar to your other PR #372 |
Member
|
@lx3133584 Please comment on above. No response will lead to this and the rest of your PRs being closed and blocked as this smells of just firing an AI at the repo with zero understanding. |
Author
|
Apologies for the confusion and noise! You're completely right — both PRs target the same underlying use case (inspecting staged response cookies on the reply before
Having both open at the same time was redundant on my part. Since Fastify core idioms favor method accessors ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When cookies are set on
replyusingreply.setCookie()orreply.cookie(), there is no way to inspect or read response cookies fromreply.cookieswithin the handler or preSerialization hooks. Although TypeScript types declarecookies: { [cookieName: string]: string | undefined }onFastifyReply, accessingreply.cookiesat runtime evaluates toundefined.Root Cause
@fastify/cookieonly registeredfastify.decorateRequest('cookies', null)on the request object. It did not define a getter forreply.cookieson the reply instance to expose the staged cookies from the internalkReplySetCookiesmap.Fix
Add a
reply.cookiesdecorator getter that returns an object mapping cookie names to their respective values from the staged response cookies map, matching the TypeScript type definition and enabling synchronous inspection of set cookies beforeonSend.Testing
test/cookie.test.jsverifyingreply.cookiesreturns set cookies and defaults to an empty object.types/index.tst.tsverifying type resolution onreply.cookies.