Skip to content

Host header output incorrect when explicitly specifying the default port #1034

@thetuxkeeper

Description

@thetuxkeeper

Hi,

if you do something like http --print hH http://localhost:80/ you get this with :80 in the host header as output:

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:80
User-Agent: HTTPie/2.4.0

But if you look at it with strace (strace -f -v -s 256 -e sendto http --print hH http://localhost:80/) you get

sendto(3, "GET / HTTP/1.1\r\nHost: localhost\r\nUser-Agent: HTTPie/2.4.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n", 130, 0, NULL, 0) = 130

So the port was removed in the actual request.
What httpie is showing is wrong in this case. It works with non-default ports, so it's just an issue with http + 80 and https + 443.

It confused me when I debugged a custom host header matching logic where I forgot to match/ignore the port.

It should both match, so there's no confusion what really is sent.

Workaround:
If you want to get the port to the host header, you have to use the header request item argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions