Skip to content

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

Open
jcomeauictx wants to merge 36 commits intopython:mainfrom
jcomeauictx:httpupgrade
Open

gh-113471: Add custom default Content-Type to http.server#113475
jcomeauictx wants to merge 36 commits intopython:mainfrom
jcomeauictx:httpupgrade

Conversation

@jcomeauictx
Copy link
Copy Markdown

@jcomeauictx jcomeauictx commented Dec 25, 2023

@ghost
Copy link
Copy Markdown

ghost commented Dec 25, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Dec 25, 2023

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.

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

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 thread Lib/http/server.py Outdated
Comment thread Lib/http/server.py Outdated
Comment thread Misc/NEWS.d/next/Library/2023-12-25-19-14-07.gh-issue-113471.ZQMpbI.rst Outdated
Copy link
Copy Markdown
Member

@encukou encukou left a comment

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 thread Lib/http/server.py Outdated
Comment thread Lib/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 thread Doc/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 and others added 7 commits March 16, 2025 04:54
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…QMpbI.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Comment thread Doc/library/http.server.rst Outdated
Co-authored-by: donBarbos <donbarbos@proton.me>
@jcomeauictx
Copy link
Copy Markdown
Author

donBarbos, I just added it, but isn't the indentation wrong?

@jcomeauictx
Copy link
Copy Markdown
Author

jcomeauictx commented Mar 16, 2025 via email

@donbarbos
Copy link
Copy Markdown
Contributor

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

@jcomeauictx
Copy link
Copy Markdown
Author

jcomeauictx commented Mar 16, 2025 via email

@github-actions
Copy link
Copy Markdown

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

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 15, 2026
@hugovk hugovk changed the title gh-113471: adds custom default content-type to http.server gh-113471: Add custom default Content-Type to http.server Apr 15, 2026
@hugovk
Copy link
Copy Markdown
Member

hugovk commented Apr 15, 2026

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 thread Doc/library/http.server.rst Outdated
Comment thread Doc/library/http.server.rst Outdated
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants