Skip to content
Open
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0d02fbe
gh-135056: Add a --cors CLI argument to http.server
aisipos May 27, 2025
1838da7
gh-issue-135056: Fix doc versionchanged and NEWS entries.
aisipos Jun 3, 2025
a3256fd
gh-13056: Allow unspecified response_headers in HTTPServer.
aisipos Jun 3, 2025
77b5fff
gh-135056: Simplifications and cleanups to http cors changes.
aisipos Jun 19, 2025
5f89c97
gh-135056: Add a --header argument to http.server cli.
aisipos Jun 20, 2025
a3243fe
gh-135056: Remove --cors opt from http.server in favor of --header
aisipos Jul 6, 2025
b1026d2
gh-135056: Use response_headers only in SimpleHTTPRequestHandler
aisipos Jul 7, 2025
6f88c13
gh-135056: Add test for http.server cli --header argument
aisipos Jul 10, 2025
7a793f2
gh-135056: Support multiple headers of the same name.
aisipos Jul 10, 2025
9450b86
gh-135056: Remove some commented out and unused code.
aisipos Jul 15, 2025
5a30d91
gh-135056: Capitalize CLI acronym in the docs.
aisipos Jul 15, 2025
d317cc2
gh-135056: Simplify args.header processing.
aisipos Jul 15, 2025
5f1fb94
gh-135056: Factor out a _make_server function from test function.
aisipos Aug 12, 2025
c376a71
gh-135056: Document directory and custom_headers as keyword args.
aisipos Aug 12, 2025
89a89f0
gh-135056: Add whatsnew entries to 3.15.rst for custom headers.
aisipos Aug 12, 2025
9653710
gh-135056: Revert document directory + custom_headers as kwargs
aisipos Oct 6, 2025
f3ae904
gh-135056: Document response_headers as an instance_attribute.
aisipos Oct 6, 2025
44efbed
gh-135056: Revert blank line removal in http.server.rst
aisipos Oct 6, 2025
d47c5a7
gh-135056: Remove incorrect = sign from whatsnew argument entry.
aisipos Oct 6, 2025
8d1286a
gh-135056: Document -H, --header cli params in http.server.rst
aisipos Oct 6, 2025
db9de68
gh-135056: Rename custom headers to extra_response_headers.
aisipos Oct 6, 2025
e149708
gh-135056: Fix alignment of parameters to _make_server.
aisipos Oct 6, 2025
c16f4c9
gh-135056: Remove extraneous newline in docstring for test() method
aisipos Oct 6, 2025
777b5b6
gh-135056: Simplify kwargs to CustomHeaderSimpleHTTPRequestHandler
aisipos Oct 6, 2025
eac5c6a
gh-135056: Note both -H and --header in NEWS entries.
aisipos Oct 6, 2025
c9c8083
gh-135056: Put kwarg on its own line in mock assertion.
aisipos Oct 7, 2025
c2d6bb3
gh-135056: Add tests for bad usage of header arg.
aisipos Oct 7, 2025
3377cf7
gh-135056: Document SimpleHTTPRequestHandler params as keyword only.
aisipos Oct 7, 2025
06a9977
gh-135056: Fix missing renames of extra_response_headers.
aisipos Oct 7, 2025
fae21f9
gh-135056: Merge branch 'main' of github.com:python/cpython
aisipos Oct 9, 2025
be78515
gh-135056: Clarify extra_response_headers is a paramter
aisipos Oct 9, 2025
53965ff
gh-135056: Prefer user-defined to user specified in http.server docs
aisipos Oct 9, 2025
c280ed8
gh-135056: Clarify wording about non-200 response header logic
aisipos Oct 9, 2025
64122df
gh-135056: Keep TLS arguments to _make_server on the same line.
aisipos Oct 9, 2025
f0d1bac
gh-135056: Prefer "specified" to "use" in cli --help text.
aisipos Oct 9, 2025
e99780e
gh-135056: Change new arg to mock.patch.object to positional instead
aisipos Oct 9, 2025
2e829bb
gh-135056: Correct proper 2 line spacing after test class.
aisipos Oct 9, 2025
8baa875
gh-135056: Assert response.status is 200 in new tests.
aisipos Oct 9, 2025
7856d27
gh-135056: Add test_extra_response_headers_missing_on_404
aisipos Oct 9, 2025
303ab5b
gh-135056: Augment header test case to check colons and spaces
aisipos Oct 10, 2025
ed0b0b3
gh-135056: Fix ReST fully qualified ref to SimpleHTTPRequestHandler
aisipos Oct 10, 2025
79c577b
gh-135056: Fix socket closing in test_extra_response_headers_arg
aisipos Oct 10, 2025
526e499
Merge remote-tracking branch 'upstream/main'
aisipos Dec 12, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-13056: Allow unspecified response_headers in HTTPServer.
This fixes the breakage to HttpServer as used by wsgiref.
  • Loading branch information
aisipos committed Jun 3, 2025
commit a3256fd21ba1d1c420e77a0007bea186a2f1f6a2
7 changes: 5 additions & 2 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class HTTPServer(socketserver.TCPServer):
allow_reuse_port = True

def __init__(self, *args, response_headers=None, **kwargs):
self.response_headers = response_headers if response_headers is not None else {}
self.response_headers = response_headers
super().__init__(*args, **kwargs)

def server_bind(self):
Expand All @@ -131,7 +131,10 @@ def server_bind(self):
def finish_request(self, request, client_address):
"""Finish one request by instantiating RequestHandlerClass."""
args = (request, client_address, self)
kwargs = dict(response_headers=self.response_headers) if self.response_headers else dict()
kwargs = {}
response_headers = getattr(self, 'response_headers', None)
if response_headers:
kwargs['response_headers'] = self.response_headers
self.RequestHandlerClass(*args, **kwargs)

class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
Expand Down
Loading