Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httplib: wrong Host header when connecting to IPv6 litteral URL #49361

Closed
gdesmott mannequin opened this issue Jan 30, 2009 · 8 comments
Closed

httplib: wrong Host header when connecting to IPv6 litteral URL #49361

gdesmott mannequin opened this issue Jan 30, 2009 · 8 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@gdesmott
Copy link
Mannequin

gdesmott mannequin commented Jan 30, 2009

BPO 5111
Nosy @orsenthil, @pitrou, @vstinner, @merwok
Files
  • 5111.diff: patch file
  • 5311_test.diff: test_httplib patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/orsenthil'
    closed_at = <Date 2010-11-14.03:33:09.920>
    created_at = <Date 2009-01-30.16:48:57.723>
    labels = ['type-bug', 'library']
    title = 'httplib: wrong Host header when connecting to IPv6 litteral URL'
    updated_at = <Date 2010-11-14.03:33:09.919>
    user = 'https://bugs.python.org/gdesmott'

    bugs.python.org fields:

    activity = <Date 2010-11-14.03:33:09.919>
    actor = 'orsenthil'
    assignee = 'orsenthil'
    closed = True
    closed_date = <Date 2010-11-14.03:33:09.920>
    closer = 'orsenthil'
    components = ['Library (Lib)']
    creation = <Date 2009-01-30.16:48:57.723>
    creator = 'gdesmott'
    dependencies = []
    files = ['14425', '14430']
    hgrepos = []
    issue_num = 5111
    keywords = ['patch']
    message_count = 8.0
    messages = ['80827', '80829', '90005', '90006', '90016', '90028', '121132', '121173']
    nosy_count = 7.0
    nosy_names = ['orsenthil', 'pitrou', 'vstinner', 'dmorr', 'eric.araujo', 'gdesmott', 'chkneo']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5111'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @gdesmott
    Copy link
    Mannequin Author

    gdesmott mannequin commented Jan 30, 2009

    To reproduce:

    • Launch a HTTP server listening on an Inet6 socket on, say, port 5555
    • Try to connect using the IPv6 loopback:
      http = httplib.HTTPConnection('[::1]:5555')
      http.request('GET', '/foo')
      r = http.getresponse()
      print r.status
    • You get 400 (bad-request) instead of 404

    It seems that's because the HTTP request is wrong. Python sends this header:
    Host: ::1:5555
    but it should be:
    Host: [::1]:5555

    I'm using python 2.5.2-1ubuntu1 on Intrepid.

    @gdesmott gdesmott mannequin added the stdlib Python modules in the Lib dir label Jan 30, 2009
    @gdesmott
    Copy link
    Mannequin Author

    gdesmott mannequin commented Jan 30, 2009

    Actually, this bug is present when you try to connect to any URL
    containing an IP6 and a port.

    So, we have the same problem when using, for example:
    http = httplib.HTTPConnection('[2a01:8790:16d:0:218:de87:164:8745]:5555')

    but
    http = httplib.HTTPConnection('[2001:4860:0:1001::68]:80')

    does work. Probably because we use the default HTTP port.

    @gdesmott gdesmott mannequin changed the title httplib: wrong Host header when connecting to IPv6 loopback httplib: wrong Host header when connecting to IPv6 litteral URL Jan 30, 2009
    @chkneo
    Copy link
    Mannequin

    chkneo mannequin commented Jul 2, 2009

    As per the RFC 2732 host header should be wrapped with []. I am
    attaching patch for this too which is applied on trunk(2.7)

    @chkneo chkneo mannequin added the type-bug An unexpected behavior, bug, or error label Jul 2, 2009
    @chkneo
    Copy link
    Mannequin

    chkneo mannequin commented Jul 2, 2009

    RFC 2732 Section three have the following details.

          host          = hostname | IPv4address | IPv6reference
          ipv6reference = "[" IPv6address "]"

    The patch contains check for : and adding the brackets

    @pitrou
    Copy link
    Member

    pitrou commented Jul 2, 2009

    Thanks for the patch. It would be better if you also added a test to
    Lib/test/test_httplib.py (unless for some reason it's technically
    impossible to do so).

    @chkneo
    Copy link
    Mannequin

    chkneo mannequin commented Jul 2, 2009

    Attaching the test patch

    @orsenthil orsenthil self-assigned this Oct 18, 2010
    @orsenthil
    Copy link
    Member

    Fixed in r86450 (py3k). Will be back porting shortly.

    @orsenthil
    Copy link
    Member

    r86461 (release31-maint)
    r86462 (release27-maint)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants