-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable rewrite_response to modify status and headers #300
Enable rewrite_response to modify status and headers #300
Conversation
@@ -40,10 +39,14 @@ def mappathf(path): | |||
'python-gzipserver': { | |||
'command': ['python3', './tests/resources/gzipserver.py', '{port}'], | |||
}, | |||
'python-http-rewrite-response': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add tests here for code, headers, etc as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test, and then we're good to go!
@@ -46,7 +46,7 @@ def __init__(self, *args, **kwargs): | |||
self.host_allowlist = kwargs.pop('host_allowlist', ['localhost', '127.0.0.1']) | |||
self.rewrite_response = kwargs.pop( | |||
'rewrite_response', | |||
lambda host, port, path, response: response.body | |||
lambda request, host, port, path, response: {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes me really nervous to see a mutable object inside a default argument. But in this case I think it's effectively immutable thanks to the lambda
.
I really like the extra functionality that this adds, thanks @ryanlovett! I feel wary about this dictionary and the large number of function arguments flying around, and I wonder if we can do better... What if we create a In addition to making the code simpler, this would also make it easy to compose rewrite functions. |
While thinking through @maresb's point about unweily arguments, I realized what we should do is use
|
Hmm, I'm quite fond of the ability to chain rewrites in my implementation. Do you see any way to achieve this with |
@maresb can you tell me a bit more about what you mean by 'chained rewrites'? An example would be lovely. |
@yuvipanda, answered in #301. |
This builds on @maresb 's work in #209 and enables one to also alter response HTTP headers and status code/reason. Thanks to @yuvipanda for the idea!