Skip to content

add port back to host arguments (sends correct host-header, fixes redirects)#218

Open
bablokb wants to merge 3 commits into
adafruit:mainfrom
bablokb:fix-host-header
Open

add port back to host arguments (sends correct host-header, fixes redirects)#218
bablokb wants to merge 3 commits into
adafruit:mainfrom
bablokb:fix-host-header

Conversation

@bablokb

@bablokb bablokb commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

The current version of request() strips the port from the host-part of the url. Subsequently, _send_request() sends a wrong host-header. Also when relative redirects are processed, the missing original port will redirect to a wrong url.

@bablokb

bablokb commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Can someone check this please? It seems the tests are confused by the additional port information. The PR could be changed to only include the port if the port is not a standard port, but this would bloat the code without functional benefits.

@justmobilize

Copy link
Copy Markdown
Collaborator

@bablokb you'll need to update all the tests. Random example:

sock.send.assert_has_calls(
[
mock.call(b"Host"),
mock.call(b": "),
mock.call(b"wifitest.adafruit.com"),
mock.call(b"\r\n"),
]
)

If we sent the port on all of these, then we'll need to update all the tests.

I also don't think a single if statement for a non-standard port would add that much bloat

@bablokb

bablokb commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@justmobilize I changed the code: the hostname is passed as is (except to the socket-constructor), so the tests don't fail since they don't see the port anymore.

@justmobilize

Copy link
Copy Markdown
Collaborator

@bablokb is it possible to add a test that hits that block?

@bablokb

bablokb commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

For someone who knows how to write and verify tests, certainly. But this is currently beyond my reach. From what the code does, it would be sufficient to pass a hostname:port combination, e.g. www.adafruit.com:80 or www.adadruit.com:443. Although these are the default ports, they get passed since the port is provided explicitly.

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

Successfully merging this pull request may close these issues.

2 participants