[Python-Dev] Allow custom headers in `http.server`

503 views
Skip to first unread message

Alex Yursha

unread,
Oct 26, 2019, 10:36:05 AM10/26/19
to pytho...@python.org
Hi CPython maintainers,

I need to test my CORS setup and looking for a possibility to set a custom Access-Control-Allow-Origin header in http.server. As of now, there is no such feature. Are you interested in me writing a patch to contribute a feature of setting custom headers directly to `http.server`?

Best,
- Alex

Oleg Broytman

unread,
Oct 26, 2019, 11:06:37 AM10/26/19
to Alex Yursha, pytho...@python.org
Hello.

This mailing list is to work on developing Python (adding new
features to Python itself and fixing bugs); if you're having problems
learning, understanding or using Python, please find another forum.
Probably python-list/comp.lang.python mailing list/news group is the
best place; there are Python developers who participate in it; you may
get a faster, and probably more complete, answer there. See
https://www.python.org/community/ for other lists/news groups/fora.
Thank you for understanding.

On Sat, Oct 26, 2019 at 03:29:03PM +0300, Alex Yursha <alexy...@gmail.com> wrote:
> Hi CPython maintainers,
>
> I need to test my CORS setup and looking for a possibility to set a
> custom *Access-Control-Allow-Origin
> *header in http.server. As of now, there is no such feature. Are you
> interested in me writing a patch to contribute a feature of setting custom
> headers directly to `http.server`?

You can override method ``send_headers`` of the class
``HTTPRequestHandler`` and add your own headers. See an example at

https://docs.aws.amazon.com/polly/latest/dg/example-Python-server-code.html

> Best,
> - Alex

Oleg.
--
Oleg Broytman https://phdru.name/ p...@phdru.name
Programmers don't die, they just GOSUB without RETURN.
_______________________________________________
Python-Dev mailing list -- pytho...@python.org
To unsubscribe send an email to python-d...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/pytho...@python.org/message/SSJL2BEQNII23ZGMLAXWYJYKTK35H6TO/
Code of Conduct: http://python.org/psf/codeofconduct/

Guido van Rossum

unread,
Oct 26, 2019, 11:10:49 AM10/26/19
to Alex Yursha, Python-Dev
Is this not something you can do yourself by calling send_header() after calling send_response()?

_______________________________________________
Python-Dev mailing list -- pytho...@python.org
To unsubscribe send an email to python-d...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/


--
--Guido van Rossum (python.org/~guido)

Alex Yursha

unread,
Oct 26, 2019, 12:35:36 PM10/26/19
to gu...@python.org, Python-Dev
I thought about adding it as a command line option when invoked as `python3 -m http.server`.

Kyle Stanley

unread,
Oct 26, 2019, 10:51:05 PM10/26/19
to Oleg Broytman, Alex Yursha, Python Dev
> Probably python-list/comp.lang.python mailing list/news group is the
best place

Since this involves a potential suggested change (adding a feature to assign custom headers to http.server), python-ideas or the "Ideas" section of https://discuss.python.org/ would also be appropriate.
Reply all
Reply to author
Forward
0 new messages