Skip to content

Stricter error reporting for malformed headers #918

Closed
@NHDaly

Description

@NHDaly

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! 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions