-
Notifications
You must be signed in to change notification settings - Fork 5
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
callback addon: support intercepting requests #105
Conversation
There is now `callback_request_url` to intercept requests and `callback_response_url` to intercept responses. All code currently intercepts responses only.
# The response to this request can control what gets returned to the client. The response object: | ||
# { | ||
# "respond_status_code": 200, | ||
# "respond_body": { "some": "json_object" } | ||
# } | ||
# If {} is sent back, the response is not modified. Likewise, if `respond_body` is set but | ||
# `respond_status_code` is not, only the response body is modified, not the status code, and vice versa. |
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.
This only applies to callback_response_url
, right?
I think it might be clearer to document the request and response for the two URLs completely separately, even if there's a bit of duplication.
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.
Yes.
Sounds good, I'm going to document this in the README where it's more easily accessible. But that will be in the next PR.
"callback_request_url": "", | ||
"callback_response_url": "", |
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.
given that the whole thing is a Callback, the callback_
prefix for these names seems a bit redundant? YMMV
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.
I prefix this on purpose because there are a lot of request/response keys flying around (the ones you register with the addon, the ones passed in as req body to the callback server, the res body from the callback server) and I've tried to use callback_
for configuring the callback server, respond_
for the response body from the callback server and no special prefix for the callback data itself.
"callback_request_url": "", | ||
"callback_response_url": "", |
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.
seems like the options are, well, optional (we use config.get()
rather than config[]
) -- so maybe just omit these?
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.
They are optional but in absence of having __init__
set all the properties, I've tried to set them all in load
, so readers can see what properties the addon uses. They aren't strictly required though as you say.
Co-authored-by: Richard van der Hoff <[email protected]>
This PR modifies the
callback
mitmproxy addon to allow it to be able to intercept outbound requests before they reach the server. This is the final piece of functionality required in order to get rid of thestatus_code
addon which has historically been used in tests to block outbound requests.The callback server has now been split into two URLs depending on if you want to intercept requests or responses.
Add a test to ensure blocking works correctly.