-
Notifications
You must be signed in to change notification settings - Fork 112
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
Allow not validating target #456
Allow not validating target #456
Conversation
lib/mint/http1.ex
Outdated
* `:skip_target_validation` - (boolean) if set to `true` the target of a request | ||
will not be validated. You might want this if you deal with non standard- | ||
conform URIs but need to preserve them. The default is to validate the request | ||
target. *Available since v1.?.?* |
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.
Added it to keep on par with case_sensititve_headers
but I'm not sure if this would be v 1.7.0 if it was released (technically it's a feature).
Also, should I add it to the Changelog then? 🤔
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.
1.7.0 is fine, but we will add it to the changelog when cutting a release.
Pull Request Test Coverage Report for Build 6ec9faaaab89127f26cfdc07c14d49992b33d7ce-PR-456Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
lib/mint/http1/request.ex
Outdated
@@ -3,9 +3,9 @@ defmodule Mint.HTTP1.Request do | |||
|
|||
import Mint.HTTP1.Parse | |||
|
|||
def encode(method, target, headers, body) do | |||
def encode(method, target, headers, body, skip_target_validation \\ false) do |
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.
this duplicates the default but I didn't:
- want it to be forced to be passed along
- break the existing interface (although technically it's
@moduledoc false
)
Also opted for a plain boolean, could also be turned into an opts
/kwlist but seemed simpler so far.
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.
Let's enforce this argument, this is a private interface. Also, if we can, we could move the call to validate_target!/1
over to Mint.HTTP
, before calling Request.encode
. That way, Request
doesn't even need to know about the new option?
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 try moving it over, the case sensitive headers option is also handled purely in Mint.HTTP
- wasn't sure about the separation of concerns. Thanks for the feedback!
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.
Moved it over after a short coffee break ☕
One thing that is slightly odd now is that target validation is in Mint.HTTP1
while header validation is still in Mint.HTTP1.Request
:
defp encode_headers(headers) do
Enum.reduce(headers, "", fn {name, value}, acc ->
validate_header_name!(name)
validate_header_value!(name, value)
[acc, name, ": ", value, "\r\n"]
end)
end
Might be worth to move. The reason I didn't yet is because it'd mean enumerating the headers another time and I'm not sure if that's a performance concern that matters in mints
context (generally it shouldn't matter for "normal" amounts of headers but yeah).
Also it'd mean me changing more code that I don't know super well :)
Happy to change or keep depending on what you think @whatyouhide !
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.
Let's keep it this way, don't worry about it for now.
@@ -548,7 +548,7 @@ defmodule Mint.HTTP1Test do | |||
request_string(""" | |||
GET / HTTP/1.1 | |||
host: localhost:#{port} | |||
user-agent: mint/#{Mix.Project.config()[:version]} | |||
user-agent: #{mint_user_agent()} |
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.
This is just a small convenience change I made in a separate commit - hope it's not too much noise but I also didn't wanna do it in a separate PR. Happy to roll it back!
As discussed in elixir-mint#453 I tried to follow the guidance of `case_sensitive_headers` so that these options are treated somewhat similarly.
2adaf60
to
573a863
Compare
Sorry for the force push, forgot one guiding comment and wanted to have it gone form history 😅 |
Works as expected on the
edit: Got it working with Req/Finch:
cc: @wojtekmach 🎉 |
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.
Looking already great 💟
lib/mint/http1.ex
Outdated
* `:skip_target_validation` - (boolean) if set to `true` the target of a request | ||
will not be validated. You might want this if you deal with non standard- | ||
conform URIs but need to preserve them. The default is to validate the request | ||
target. *Available since v1.?.?* |
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.
1.7.0 is fine, but we will add it to the changelog when cutting a release.
lib/mint/http1/request.ex
Outdated
@@ -3,9 +3,9 @@ defmodule Mint.HTTP1.Request do | |||
|
|||
import Mint.HTTP1.Parse | |||
|
|||
def encode(method, target, headers, body) do | |||
def encode(method, target, headers, body, skip_target_validation \\ false) do |
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.
Let's enforce this argument, this is a private interface. Also, if we can, we could move the call to validate_target!/1
over to Mint.HTTP
, before calling Request.encode
. That way, Request
doesn't even need to know about the new option?
Co-authored-by: Andrea Leopardi <[email protected]>
@PragTob do we need to do this for HTTP/2 too? |
@whatyouhide I'm unsure :) I'm guessing so but I didn't find any similar code with HTTP2 on a cursory look and I'm also not as familiar with HTTP2, let me see if I can find something. |
@whatyouhide as best as I can see there is no validation going on in the HTTP2 implementation.
Lines 510 to 527 in 8516bcd
and only passed on to this function where it is just added to the header: Lines 1354 to 1370 in 8516bcd
there are some further validations going on, but as far as I can see none of them are for the path in particular/for a similar problem. |
Coolsies, then we're good 🙃 |
As discussed in #453
I tried to follow the guidance of
case_sensitive_headers
sothat these options are treated somewhat similarly.
I tried to keep with the patterns of surrounding code, if you want anything changed/I missed something - happy to do so!
In a separate commit I also included a small nicety as I saw the definition of the mint user agent duplicated over the tests. Happy to roll that back though.
Some questions/remarks inline.
Thanks for all your work! 💚
Tasks left for me: