I’m using SimpleHTTPServer to test some webpages I’m working on. It works great, however I need to do some cross-domain requests. That requires setting a Access-Control-Allow-Origin header with the domains the page is allowed to access.
Is there an easy way to set a header with SimpleHTTPServer and serve the original content? The header would be the same on each request.
This is a bit of a hack because it changes
end_headers()behavior, but I think it’s slightly better than copying and pasting the entireSimpleHTTPServer.pyfile.My approach overrides
end_headers()in a subclass and in it callssend_my_headers()followed by calling the superclass’send_headers().It’s not 1 – 2 lines either, less than 20 though; mostly boilerplate.