classification
Title: Allow IPv6 bind in http.server
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jaraco Nosy List: Link Mauve, berker.peksag, demian.brecht, gregory.p.smith, jaraco, jleedev, lisroach, martin.panter, masthana, rpodgorny
Priority: normal Keywords: patch

Created on 2015-05-16 13:54 by Link Mauve, last changed 2019-02-07 13:28 by jaraco. This issue is now closed.

Files
File name Uploaded Description Edit
ipv6.patch Link Mauve, 2015-05-16 13:54 Patch adding IPv6 support to http.server. review
Pull Requests
URL Status Linked Edit
PR 10595 merged lisroach, 2018-11-19 02:52
PR 11767 merged jaraco, 2019-02-06 01:33
PR 11767 merged jaraco, 2019-02-06 01:33
PR 11767 merged jaraco, 2019-02-06 01:33
Messages (6)
msg243317 - (view) Author: (Link Mauve) Date: 2015-05-16 13:54
When running `python -m http.server -b ::` (or any other IPv6), I’d expect people to be able to download from my IPv6.

This patch fixes that issue.

I also tested it on a dual-stack kernel, IPv4 requests work just fine and appear as ::ffff:127.0.0.1 for example.
msg243883 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-05-23 03:53
I am no IPv6 expert, but this looks like a reasonable first approximation. The “http.server” module documentation should also be updated to say IPv6 addresses are supported on the command line, and I guess there should be a test case added.

But maybe see Lib/smtpd.py line 657 for how this is done in a more general way for the SMTP server module (Issue 14758), using getaddrinfo(). There is also Issue 20215 proposing to do something equivalent in the lower level “socketserver” module, which would probably make this change redundant.

It would also be nice for it to bind to both IPv4 and IPv6 if possible, but that is apparently not easy to do cross platform; see Issue 3213.
msg315853 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2018-04-27 18:35
From what I can tell, there's not currently any tests for the behavior of `http.server` as a script, and that sounds like a non-trivial behavior to test. I agree documentation updates for this change are essential, but I'd suggest a test is too high a burden to ask for a change like this when there aren't already tests exercising the related functionality.
msg330071 - (view) Author: Lisa Roach (lisroach) * (Python committer) Date: 2018-11-19 02:54
Looks like the original author isn't around anymore (feel free to chime in if you are, Link!), so I went ahead and made a PR. I added a quick unit test, it's not much but more than nothing, plus updated the documentation.
msg334897 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2019-02-06 00:53
I don't believe the current patch as accepted has the right behaviors. First off, the default behavior, which indicates "all interfaces" only binds to IPv4 interfaces. Additionally, "-b localhost" only binds to IPv4 localhost.

Ideally, the bind should happen on all stacks unless a specific stack is indicated.
msg335020 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2019-02-07 13:22
New changeset f289084c83190cc72db4a70c58f007ec62e75247 by Jason R. Coombs in branch 'master':
bpo-24209: In http.server script, rely on getaddrinfo to bind to preferred address based on the bind parameter. (#11767)
https://github.com/python/cpython/commit/f289084c83190cc72db4a70c58f007ec62e75247
History
Date User Action Args
2019-02-07 13:28:36jaracosetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-02-07 13:22:49jaracosetmessages: + msg335020
2019-02-06 01:33:41jaracosetstage: resolved -> patch review
pull_requests: + pull_request11728
2019-02-06 01:33:26jaracosetstage: resolved -> resolved
pull_requests: + pull_request11727
2019-02-06 01:33:11jaracosetstage: resolved -> resolved
pull_requests: + pull_request11726
2019-02-06 00:53:43jaracosetassignee: jaraco
messages: + msg334897
2018-11-26 18:44:45lisroachsetstage: patch review -> resolved
2018-11-19 03:45:00gregory.p.smithsetversions: + Python 3.8, - Python 3.6
2018-11-19 02:54:20lisroachsetnosy: + lisroach
messages: + msg330071
2018-11-19 02:52:35lisroachsetstage: test needed -> patch review
pull_requests: + pull_request9840
2018-10-23 21:06:22masthanasetnosy: + masthana
2018-10-10 15:32:39rpodgornysetnosy: + rpodgorny
2018-04-27 18:35:04jaracosetmessages: + msg315853
2018-04-27 18:15:46jaracosetnosy: + jaraco
2017-01-25 22:21:26gregory.p.smithsetnosy: + gregory.p.smith
2016-04-04 23:03:09jleedevsetnosy: + jleedev
2015-05-23 19:01:22berker.peksagsetnosy: + berker.peksag

versions: - Python 3.5
2015-05-23 03:53:05martin.pantersetstage: test needed
messages: + msg243883
versions: - Python 3.4
2015-05-22 16:40:05demian.brechtsetnosy: + demian.brecht
2015-05-16 22:51:57martin.pantersetnosy: + martin.panter
2015-05-16 13:54:45Link Mauvecreate