-
-
Notifications
You must be signed in to change notification settings - Fork 158
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 where session cookie was not always written at the right time. #1160
Fix bug where session cookie was not always written at the right time. #1160
Conversation
We'll also need to update Lucky CLI to remove |
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.
So glad you found the issue! This looks great to me. I just left a few small comments, but then I think it's good to go.
@@ -196,7 +198,7 @@ module Lucky::Renderable | |||
{% raise "'text' in actions has been renamed to 'plain_text'" %} | |||
end | |||
|
|||
@[Deprecated("`render_text deprecated. Use `plain_text` instead")] | |||
@[Deprecated("`render_text` deprecated. Use `plain_text` instead")] |
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.
👍
@@ -67,6 +159,11 @@ private def print_response(context : HTTP::Server::Context, status : Int32?) | |||
print_response_with_body(context, "", status) | |||
end | |||
|
|||
private def print_response_with_body(context : HTTP::Server::Context, body = "", status = 200, content_type = "text/html") | |||
private def print_response_with_body( | |||
context : HTTP::Server::Context, |
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.
Did the formatter do this? I ask because the one below has the first arg start on the same line as the signature. I'm thinking maybe we make them the same (one way or the other). I was curious if the formatter allowed both, or if it prefers one vs the other way. Does that make sense?
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.
I tend to put the first argument on a new line if everything does not fit on the same line. But the formatter does respect that and will put all following arguments on the same indentation level.
I like it because that will consistently put all multi-line arguments on the same indentation throughout the file. Otherwise, they are hanging at different places, sometimes with odd-numbered indentation levels, depending on the length of the name of the method.
Here again, if you prefer the first argument at the same line as the method, I'll change that.
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.
BTW, I have been moving a lot of code around there, because that's where I initially added the changes. But then I realised it should be somewhere else. That's why it has been changed.
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.
I think this look good 👍
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.
I'm ok with doing this. Should we do the same on https://github.com/luckyframework/lucky/pull/1160/files#diff-a949f27bf5c58356d03de361bcf6cba2R182 as well?
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.
That would be cleaner indeed, so I added those changes as well.
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.
Looks good! Just need to handle flash and I think it is good to go. Thanks for investigating + fixing.
Do you know why it wasn't working before, but it worked this time? Was it that it changed to the TextResponse
class? Just trying to make sure I understand why this works but it didn't work when done in Renderable
@@ -20,6 +20,8 @@ class Lucky::TextResponse < Lucky::Response | |||
end | |||
|
|||
def print : Nil | |||
write_session | |||
write_cookies |
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.
Now that cookies/session are set here, I think the flash handler should also be removed and the flash set before write_session
. That way it gets written to the session cookie when it is printed.
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.
Great, I'll do that as well.
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.
Voila, that's done!
@@ -67,6 +159,11 @@ private def print_response(context : HTTP::Server::Context, status : Int32?) | |||
print_response_with_body(context, "", status) | |||
end | |||
|
|||
private def print_response_with_body(context : HTTP::Server::Context, body = "", status = 200, content_type = "text/html") | |||
private def print_response_with_body( | |||
context : HTTP::Server::Context, |
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.
I think this look good 👍
Well, yeah, that's what threw me off. I didn't realise
So I added the |
Ohhh that makes total sense. And I definitely agree on adding it to |
I'll have to look closer at it tomorrow. Specs run green, but not sure about my apps. |
Sounds good. The flash/session stuff can be a bit gnarly with edge cases so better safe than sorry 😂 Thanks for double checking and for fixing this. Can't wait to get this out |
Yeah, flash messages are a breed of their own. :) I'll have to install it into an app that uses them. More tomorrow! |
@paulcsmith I've tested flash messages throughout one app and they all work as expected, except for the following two scenarios.
|
I think this is ok to merge. Could you open issues for those 2 redirect issues? I think they are likely bugs from before that we need to fix. Thanks for the thorough investigation, and for the fix! |
Purpose
This fixes #1064.
Description
Lucky::SessionHandler
has been removedLucky::FlashHandler
has been removedLucky::TextResponse#print
I tested this on our app as well and everything works as expected now. 😌️
Checklist
crystal tool format spec src
./script/setup
./script/test