I'm currently working an a Javascript-App that has to do Cross-Origin Requests to a webservice using Werkzeug (I have access to both the javascript-client and the werkzeug-server)
Now, after some reading/searching, for my responses on the server I have added (Example-code):
response = generate_response(request)
response.headers.add('Access-Control-Allow-Origin', 'http://localhost')
My JS-App is running from http://localhost/MyApp
. This works (-> processing on serverside goes through, client receives correct data), but only if generate_response returns an instance of a class inheriting Werkzeug's BaseResponse
-Class.
But, and here is my question, if generate_response
is returning one of Werkzeugs HttpExceptions
, response
doesn't have a headers field to append to. As it seems, headers are fixed in Werkzeug-Exceptions:
class HttpException(Exception):
....
def get_headers(self, environ):
"""Get a list of headers."""
return [('Content-Type', 'text/html')]
...
Is there an easy way to fix this, as in work around that so i can append my custom header to the exception or do i have to subclass the Exception-Baseclass to add support for my headers? Is this intentional or maybe a design-issue worth reporting? And last but not least: Am i misunderstanding something here and thats not at all the way it is supposed to be done?
As of Werkzeug 1.0.0 milestone this issue has been fixed
https://github.com/pallets/werkzeug/issues/131
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With