-
-
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
Changes from 2 commits
1b01dd0
0d94590
6f2b4b9
73b1b27
4e5958b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,7 +179,9 @@ module Lucky::Renderable | |
file(path, content_type, disposition, filename, status.value) | ||
end | ||
|
||
def send_text_response(body : String, content_type : String, status : Int32? = nil) : Lucky::TextResponse | ||
def send_text_response(body : String, | ||
content_type : String, | ||
status : Int32? = 100) : Lucky::TextResponse | ||
Lucky::TextResponse.new(context, content_type, body, status: status) | ||
end | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
private def render_text(*args, **named_args) : Lucky::TextResponse | ||
plain_text(*args, **named_args) | ||
end | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Voila, that's done! |
||
context.response.content_type = content_type | ||
context.response.status_code = status | ||
gzip if should_gzip? | ||
|
@@ -42,4 +44,21 @@ class Lucky::TextResponse < Lucky::Response | |
Lucky::Server.settings.gzip_content_types.includes?(content_type) | ||
{% end %} | ||
end | ||
|
||
private def write_session : Void | ||
context.cookies.set( | ||
paulcsmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Lucky::Session.settings.key, | ||
context.session.to_json | ||
) | ||
end | ||
|
||
private def write_cookies : Void | ||
response = context.response | ||
|
||
context.cookies.updated.each do |cookie| | ||
response.cookies[cookie.name] = cookie | ||
end | ||
|
||
response.cookies.add_response_headers(response.headers) | ||
end | ||
end |
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.