selenium-wire
selenium-wire copied to clipboard
Ability to define whether response body is saved based on ContentType/StatusCode/Path
To reduce the amount of IO and maximize performance, there could be a simple rules engine that allows us to define which response bodies we are interested in via a combination of ContentType/StatusCode/Path.
e.g.
Capture response bodies for all paths and content type if the status code > 399
Capture response body if JSON, status code < 399 and path = "/path/I/am/interested/in"
Thinking out loud here: I propose using interceptors for this purpose. They give ultimate flexibility in terms of what attributes of a request can be interrogated. We'd need to introduce a new attribute on the request and response to indicate whether the body should be captured or not, e.g. capture_body
. Once that's been done, we should be able to do such things as:
def interceptor(req, res):
if res.status_code > 399:
res.capture_body = False
driver.interceptor = interceptor
driver.get(...)
and
def interceptor(req, res):
if req.path == '/path/I/am/interested/in' \
and res.headers['Content-Type'] == 'application/json' \
and res.status_code < 399:
res.capture_body = False
driver.interceptor = interceptor
driver.get(...)