-
Notifications
You must be signed in to change notification settings - Fork 22
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
Enhance Request #123
Enhance Request #123
Conversation
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've left some comments, but this looks great!
lib/rage/request.rb
Outdated
def remote_ip(*args) | ||
@env['HTTP_X_FORWARDED_FOR'] | ||
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.
I agree this is going to be more complicated. I would encourage you to work on remote_ip
in a separate PR, but that's up to you.
Essentially, we want the algorithm to be close to what it is in Rails with the ability to customize the list of trusted proxies.
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 realized that rack already includes behavior for this:
def_delegator :@rack_request, :ip, :remote_ip
It's in ip
method. Here I aliased it as remote_ip
but that seems to be what rails is relying on for that behavior.
In terms of customizing the list of trusted proxies, I think we could just hook into rack behavior:
trusted_proxies = Regexp.union(
/\A127#{valid_ipv4_octet}{3}\z/, # localhost IPv4 range 127.x.x.x, per RFC-3330
/\A::1\z/, # localhost IPv6 ::1
/\Af[cd][0-9a-f]{2}(?::[0-9a-f]{0,4}){0,7}\z/i, # private IPv6 range fc00 .. fdff
/\A10#{valid_ipv4_octet}{3}\z/, # private IPv4 range 10.x.x.x
/\A172\.(1[6-9]|2[0-9]|3[01])#{valid_ipv4_octet}{2}\z/, # private IPv4 range 172.16.0.0 .. 172.31.255.255
/\A192\.168#{valid_ipv4_octet}{2}\z/, # private IPv4 range 192.168.x.x
/\Alocalhost\z|\Aunix(\z|:)/i, # localhost hostname, and unix domain sockets
)
self.ip_filter = lambda { |ip| trusted_proxies.match?(ip) }
I'm thinking either add another Regexp.union
with rack and a list that we pass down or modify self.ip_filter
?
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.
Both options work. I guess modifying self.ip_filter
would be somewhat more expected.
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 modified the initialize
method for request
is that what you had in mind for custom proxy support?
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.
Pretty much, but it should be part of the configuration instead, same way it is in Rails - https://guides.rubyonrails.org/configuring.html#actiondispatch-remoteip.
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'll look into what I imagine to be that little configuration object but if memory serves correct I'm not sure that this module is being used anymore ill take another look, because that module resolves the remote ip but ActionDispatch request is forwarding it to rack
Also one thing I added to cover
|
As an aside. I noticed that we have
Is there a reason we don't want to use
|
No real reason. Feel free to update it. |
Hey @aaoafk , really great job so far! Sorry I wasn't able to provide prompt feedback, but I promise I will get better 😄 |
that's fine im more so just trying to get better at programming so your reviews are helping no pressure im working on this in my free time lol |
Hey @aaoafk , how's it going? Is there anything I can help you with? |
Hey @rsamoilov recently had a big life change, moved to Puerto Rico for work so I was pretty busy the last couple weeks sorting everything out. I'll try to take a look at this soon. |
I committed changes for you to view I still need to look at |
It lacks YARD docs, but apart from that, this bit looks good 👍 |
Co-authored-by: Roman Samoilov <[email protected]>
Co-authored-by: Roman Samoilov <[email protected]>
Co-authored-by: Roman Samoilov <[email protected]>
Co-authored-by: Roman Samoilov <[email protected]>
I'll look at adding YARD Docs and the custom proxies bit then |
@rsamoilov are you imagining that the |
|
Hey @aaoafk , are you still working on the PR? If you are struggling with the |
Yeah I was thinking it might take a little bit for that one I'll remove the remote ip stuff and do a push tonight |
just focused ones. Commented out the focus run option for rspec
Hey Roman. I think this should have everything around the remote_ip removed and I corrected the merge conflict, I think we just wanted to take changes from both files since they weren't really conflicting. |
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.
Hey Steven, I've left several comments to fix the tests.
Could you also fix the style warnings? Once it's done, the PR will be good to go.
spec/rage/request_spec.rb
Outdated
it "handles the protocol property of a request" do | ||
expect(request.protocol).not_to be_nil | ||
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 you remove the protocol
method from the Request
class on purpose? This test is currently failing because there's no such 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.
Strange. I added it back. I don't remember deleting it.
One test is failing now and I think it might be due to a stale value for the
The output is: expected: "http://localhost/users?show_archived=true" I think this is because of the memoized request, it is using an old value for env, since the test does a direct modification on env it wouldn't be reflected there, but some rack methods do query headers directly from env so... As an aside ill probably re-write the tests to check for literal values instead of just checking not nil... |
Aha, good catch! Those tests should use contexts instead. Do you want me to fix those? |
Do you mean rspec contexts ? |
Yep. |
How does this look? BTW the previous issue was because of 'HTTP_HOST' header being set to 'localhost:3000'. It needs to be set each time the test is using that for context otherwise it pulls from SERVER_* headers |
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.
🚢 Thank you!
Rubocop is failing, but it looks like it's picked up the wrong commit. |
🔥 I'll see about remote ip next or something else curious about the implementation |
hello,
i think this should mostly work unless i've missed something.
the only issue right now is maybe
remote_ip
needs to be thought through a little more and the current method of checking the http action does not verify againstHTTP_METHODS
I just need to port that underscore method over or just do something else.lmk your initial thoughts