-
Notifications
You must be signed in to change notification settings - Fork 276
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
Chain responses in middleware. #1620
Chain responses in middleware. #1620
Conversation
By making this change, middleware should favor headers for passing data. Cookies are in the header and update, but don't appear in the 'cookies' property, so would be reserved for passing data to future requests. |
Sorry for all the yarn.lock commits. |
@mjarosch It took us a while to get to this, sorry. I did want to ask about reading site from header. We add sc_site cookie to ensure it's used in subsequent page requests - this is a compatibility measure for Sitecore, since it reads site name from the sc_site too. We also read the value from response object:
Do you mean that cookies may be absent during middleware execution of other requests or that follow-up middleware plugins have no access to cookies? |
@art-alexeyenko Yes, I will update to remove the yarn.lock file and resolve the conflicts in personalize.
I mean follow-up middleware plugins won't have access to the cookie. The cookie is still set on the client, and future requests will see it. |
That's not what I'm seeing when testing locally - but perhaps I miss some scenarios. SITE_SYMBOL cookie is set in multisite plugin, and if you check the value in the follow up plugin like |
@art-alexeyenko I could have sworn, when I originally did this, that it wasn't there. But I validated on my original implementation and they are accessible. Should I remove the comment? |
@mjarosch perhaps this PR can just be wound down to code cleanup? There's probably no reason to duplicate site in headers and cookies - but it's good to avoid code duplication. |
@art-alexeyenko the chaining makes it so following middleware don’t need to re-set cookies. So I would consider that more than code cleanup. I can remove adding the site name to the headers. I think it’s nice to pass things in a consistent place and not everything should be set in a cookie. So I think you could justify duplicating the site in this case. I defer to your judgement on this. |
@mjarosch I'm still not sure the site should be duplicated in two places. The cookie can be used for both Sitecore instance to be consumed by, and by middleware plugins. Header will just repeat what is already set. |
@art-alexeyenko I have updated it to remove storing the site in the header. |
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.
@mjarosch thank you once again!
I left a couple small comments and pinged a dev from SXA team to give a thumbs up on redirects changes, as it's their domain. We should be able to merge once there's a green light.
Description / Motivation
By chaining the responses in rewrites, we can access headers set in earlier middleware.
Testing Details
Types of changes