Skip to content
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

Stricter error reporting for malformed headers #918

Closed
NHDaly opened this issue Aug 31, 2022 · 2 comments
Closed

Stricter error reporting for malformed headers #918

NHDaly opened this issue Aug 31, 2022 · 2 comments

Comments

@NHDaly
Copy link
Collaborator

NHDaly commented Aug 31, 2022

Please specify the following versions when submitting a bug report:

  • Julia 1.7.3
  • HTTP.jl 1.3.1
  • MbedTLS.jl 1.1.3

We had an issue where our requests weren't working as expected. We eventually debugged the issue down to a bug in how we were specifying headers - we were accidentally passing headers = ["key", "value"] instead of headers = ["key" => "value"].

This means that we were accidentally passing two separate header strings, which were being interpreted as e.g. "key"[1] => "key"[2], or 'k'=>'e' and 'v'=>'a'. You can see this in action here:

julia> HTTP.request("GET", "http://example.com", headers=["hello","world"], verbose=3);
┌ LogLevel(-1001): GET / HTTP/1.1
└ @ HTTP.StreamRequest ~/.julia/packages/HTTP/cwiB4/src/clientlayers/StreamRequest.jl:24LogLevel(-1002): client startwrite
└ @ HTTP.StreamRequest ~/.julia/packages/HTTP/cwiB4/src/clientlayers/StreamRequest.jl:25LogLevel(-1003): 👁  Start write:🔁    4s example.com:80:61559 RawFD(36)
└ @ HTTP.ConnectionPool ~/.julia/packages/HTTP/cwiB4/src/ConnectionPool.jl:229LogLevel(-1002): HTTP.Messages.Request:"""
│ GET / HTTP/1.1
│ h: e
│ w: o
│ Host: example.com
│ Accept: */*
│ User-Agent: HTTP.jl/1.7.3-pre.8
│ Content-Length: 0
│ Accept-Encoding: gzip

"""
└ @ HTTP.StreamRequest ~/.julia/packages/HTTP/cwiB4/src/clientlayers/StreamRequ

Can we have this situation print an error instead? If you pass a header value that has more than 2 elements, can that be an error? And if you pass a header value that is of type String, can that be an error? E.g. can all of these situations be errors:

HTTP.request("GET", "http://example.com", headers=["hello"], verbose=3);
HTTP.request("GET", "http://example.com", headers=[(1,2,3,4,5), (2,3,4,5,6)], verbose=3);
HTTP.request("GET", "http://example.com", headers=[1, 2], verbose=3);   # <-- this is already an error (since `1[2]` fails)
HTTP.request("GET", "http://example.com", headers=["hello", "world"], verbose=3);

Thank you! 😊

@quinnj
Copy link
Member

quinnj commented Aug 31, 2022

Thanks for the report @NHDaly! PR up: #919

@quinnj quinnj closed this as completed in 91f1241 Aug 31, 2022
@NHDaly
Copy link
Collaborator Author

NHDaly commented Aug 31, 2022

❤️ so fast. Thank you! 😊 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants