Skip to content

Httpx includes ipv6 scope in Host header #2174

@elupus

Description

@elupus

When requesting http paths with scope as part of the ipv6 address, this should stripped before being added to the http host header since it's fully local feature of the ipv6 stack.

Http over link local addresses is quite common on upnp based announces on link local networks.

Apache for example will reject the request: https://bz.apache.org/bugzilla/show_bug.cgi?id=35122
Lighthttpd: https://redmine.lighttpd.net/issues/2442

Example to reproduce:

import httpx
import respx

@respx.mock
def test_example():
    my_route = respx.get("https://[fe80::8fd:8e9a:40d8:29a6%en0]/get")
    my_route.mock(return_value=httpx.Response(204))

    r = httpx.get(r'https://[fe80::8fd:8e9a:40d8:29a6%en0]/get')

    print(my_route.calls[0].request.headers["host"])
    assert my_route.calls[0].request.headers["host"] == "[fe80::8fd:8e9a:40d8:29a6]"

test_example()

  • Initially raised as discussion #...

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