-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
RACK_URL_SCHEME calculation caring about more headers #1491
Conversation
This definitely looks like the right approach, just needs the things you already pointed out to get it over the line. |
Can this be merged? Is anything waiting on it? |
@evanphx I apologize, this had been sitting - I'll turn these TODO items into a checkbox list and then do them. When visible and less obtuse, review becomes much easier. |
769d7f9
to
05acc62
Compare
05acc62
to
98693e9
Compare
In order to get this code mergeable, I offer it as-is to review. After re-reading this change, I think it's ready. I had one question to my earlier self, who was borrowing that code. Q: Why am I splitting
|
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.
Just a few stylistic changes. Also, needs tests.
@nateberkopec I tried to interpret your comments as commits. |
08b9d9c
to
a094ba3
Compare
Note: To run one test file, saving yourself time, use
|
@nateberkopec Thanks for asking again, for tests. I sat down and had a go. |
@@ -588,8 +588,11 @@ def normalize_env(env, client) | |||
end | |||
|
|||
def default_server_port(env) | |||
return PORT_443 if env[HTTPS_KEY] == 'on' || env[HTTPS_KEY] == 'https' | |||
env['HTTP_X_FORWARDED_PROTO'] == 'https' ? PORT_443 : PORT_80 | |||
if ['on', HTTPS].include?(env[HTTPS_KEY]) || env[HTTP_X_FORWARDED_PROTO].to_s[0...5] == HTTPS || env[HTTP_X_FORWARDED_SCHEME] == HTTPS || env[HTTP_X_FORWARDED_SSL] == "on" |
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.
OK - now that we've refactored this out a bit, line 591 and the if/if/else in like 634 look really similar. Is there any possibility for re-use here?
test/test_puma_server.rb
Outdated
req['HOST'] = "example.com" | ||
req['X_FORWARDED_SSL'] = "on" | ||
|
||
res = Net::HTTP.start @host, @server.connected_port do |http| |
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.
Hmmm. This doesn't match our current style of just writing onto a TCP socket. Thoughts on 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.
Eh, I only repeated test bodies which were there, tests that checked similar things, to have something to start with.
When I refactor this, I'll try to narrow down the tests to be more about the methods I changed.
test/test_puma_server.rb
Outdated
end | ||
|
||
def test_respect_x_forwarded_scheme | ||
@server.app = proc do |env| |
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.
Once my other comment is resolved - the setup in all of these is so similar, we should extract to a helper method.
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'd be glad to!
test/test_puma_server.rb
Outdated
http.request(req) | ||
end | ||
|
||
assert_equal "80", res.body |
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 wonder - why not just test the actual methods modified rather than test res.body? This test is testing a lot more than it has to.
3dc47ed
to
329f00e
Compare
@nateberkopec I took a closer look, and made follow-up commits. |
🚢 🚢 🚢 |
Thanks for all your hard work here, @olleolleolle ! |
This PR is about #1179, as a way of pushing the discussion onwards.
const.rb
and use themRACK_URL_SCHEME
is now read from a series of HTTP headers (just like Rack does it)