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 bug/code smell where GA cookie is set after a server redirect #253

Merged
merged 3 commits into from
Jul 3, 2020

Conversation

yong-jie
Copy link
Member

@yong-jie yong-jie commented Jul 3, 2020

Problem

When a new visitor without a GA cookie visits a short link, the server attempts to set a cookie after a response has already taken place. This results in a HTTP 500 Internal Server Error being logged when in fact a HTTP 302 Redirect has already been returned to the client.

Closes #250

Solution

  • Move cookie generation and setting to another place before setting res
  • Don't create a new logRedirect function in every redirect
  • Don't pass res and req into other functions
  • Fix broken tests

Copy link
Contributor

@LoneRifle LoneRifle left a comment

Choose a reason for hiding this comment

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

we probably should follow up to rework this for readability. For now, in the interests of minimising change, this would be fine.

src/server/controllers/RedirectController.ts Show resolved Hide resolved
@yong-jie yong-jie marked this pull request as ready for review July 3, 2020 05:33
@yong-jie
Copy link
Member Author

yong-jie commented Jul 3, 2020

Acknowledged that code refactors are not the priority in this PR, and will be addressed in a separate PR after today's release.

@yong-jie yong-jie merged commit 8c86b11 into develop Jul 3, 2020
@yong-jie yong-jie deleted the fix-res-cookie branch July 3, 2020 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix bug where GA cookie is set after a server redirect
3 participants