Skip to content

gh-113471: Add custom default Content-Type to http.server - #113475

Merged
hugovk merged 40 commits into
python:mainfrom
jcomeauictx:httpupgrade
Apr 30, 2026
Merged

gh-113471: Add custom default Content-Type to http.server#113475
hugovk merged 40 commits into
python:mainfrom
jcomeauictx:httpupgrade

Conversation

@jcomeauictx

@jcomeauictxjcomeauictx commented Dec 25, 2023

Copy link
Copy Markdown

@ghost

ghost commented Dec 25, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change need tests.

I am not sure how much useful is this feature. It only allows to override the MIME type of unrecognized types. And would not it be simpler to configure your browser?

Comment threadLib/http/server.py Outdated
Comment threadLib/http/server.py Outdated
Comment threadMisc/NEWS.d/next/Library/2023-12-25-19-14-07.gh-issue-113471.ZQMpbI.rst Outdated

@encukouencukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The feature looks useful to me; I've wanted it once or twice before. However, adding it would be a lot work. Not sure if it's worth your time.

The change needs documentation (in Doc/library/http.server.rst, both for the attribute and CLI option).

Comment threadLib/http/server.py Outdated
Comment threadLib/http/server.py Outdated
@donbarbos

Copy link
Copy Markdown
Contributor

@jcomeauictx are you going to continue working on this PR?

@jcomeauictx

Copy link
Copy Markdown
Author

@jcomeauictx are you going to continue working on this PR?

I've forgotten what else needs to be done. And in any case, nobody else seems interested in it.

Comment threadDoc/library/http.server.rst Outdated

python -m http.server --default-content-type text/html

.. versionchanged:: 3.13

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.

Suggested change
.. versionchanged:: 3.13
.. versionchanged:: next

@donbarbos

Copy link
Copy Markdown
Contributor

I've forgotten what else needs to be done. And in any case, nobody else seems interested in it.

I'm interested :)
I think if you add tests you can ping someone from core members

@jcomeauictx

Copy link
Copy Markdown
Author

OK, I'll look into it tomorrow. No idea where to add them, though, or what precisely needs to be tested.

@jcomeauictx

jcomeauictx commented Mar 16, 2025 via email

Copy link
Copy Markdown
Author

@donbarbos

Copy link
Copy Markdown
Contributor

Sorry I can't. I mean move on to the rest options

@jcomeauictx

jcomeauictx commented Mar 16, 2025 via email

Copy link
Copy Markdown
Author

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 15, 2026
@hugovkhugovk changed the title gh-113471: adds custom default content-type to http.servergh-113471: Add custom default Content-Type to http.serverApr 15, 2026
@hugovk

Copy link
Copy Markdown
Member

I've resolved the merge conflict and pushed some minor docs things.


default_content_type is defined on BaseHTTPRequestHandler, but only used in its subclass SimpleHTTPRequestHandler, in guess_type().

Should default_content_type be moved to SimpleHTTPRequestHandler?

Also, test() defaults HandlerClass=BaseHTTPRequestHandler, but the CLI calls it with HandlerClass=SimpleHTTPRequestHandler.

test() then sets HandlerClass.default_content_type. This doesn't matter to BaseHTTPRequestHandler if we move it, although we could also change test() to only use SimpleHTTPRequestHandler?

@jcomeauictx

Copy link
Copy Markdown
Author

I think I had a reason to put it in BaseRequestHandler, but it's been a long time and I've moved on to other things. Do what seems best.

Comment threadDoc/library/http.server.rst Outdated
Comment threadDoc/library/http.server.rst Outdated
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@read-the-docs-community

read-the-docs-communityBot commented Apr 29, 2026

Copy link
Copy Markdown

@hugovk
hugovk requested a review from AA-Turner as a code ownerApril 29, 2026 13:33
@hugovk
hugovk merged commit cc5f8b5 into python:mainApr 30, 2026
51 checks passed
@hugovk

Copy link
Copy Markdown
Member

Thanks!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

staleStale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@jcomeauictx@donbarbos@hugovk@encukou@serhiy-storchaka@picnixz