Skip to content

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

Merged
dhalbert merged 4 commits into
adafruit:mainfrom
bablokb:fix-host-header
Oct 30, 2026
Merged

dhalbert merged 4 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.

@bablokb

bablokb commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

I just don't understand why this is not merged. Just do the maths: you have two known serious bugs now and no tests, and with this PR you have no (known) bugs and still no tests, which seems like a huge improvement to me.

I always thought this is one of the core libraries, but Adafruit seems to prefer to keep bugs and kill community involvement.

@dhalbert

Copy link
Copy Markdown
Contributor

I always thought this is one of the core libraries, but Adafruit seems to prefer to keep bugs and kill community involvement.

Of course we don't prefer to keep bugs. This seems to have slipped under the radar because we were hoping for a test. We can have an LLM make a test quickly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. A ping rather than anger would be preferred.

@dhalbert
dhalbert merged commit d01449e into adafruit:main Oct 30, 2026
1 check passed
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 31, 2026
Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 4.1.18 from 4.1.17:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#218 from bablokb/fix-host-header
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#219 from MakerClassCZ/response-raw

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_JamPacked
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.

3 participants