-
Notifications
You must be signed in to change notification settings - Fork 123
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
Not possible to make an heuristic depend on the request. #131
Comments
I know this is an old issue but I think supporting this could be beneficial. I see no reason why the request couldn't be made available to the heuristic. I'm happy to make a PR for it :) |
As it has been a while, I could be wrong, but I think there were some difficulties taking the urllib3 response and converting it to the requests response and back again b/c of the file handle for the response body. When I did look, there wasn't really anything that was missing pers, it just required a different API. That said, I'm happy to look at any PRs to improve the heuristics, including a higher level abstraction that might be helpful. I'd only ask that if anyone does have any radical ideas, lets chat about it in a ticket before spending too much time in the code. |
Thanks for replying @ionrock ! Essentially I'm thinking of passing in the class BaseHeuristic(object):
def warning(self, request, response):
...
def update_headers(self, request, response):
...
def apply(self, request, response):
... That would then allow for heuristics that, for example, take into account query parameters. A trivial example: class NeverCacheParameterHeuristic(BaseHeuristic):
def update_headers(self, request, response):
if "never_cache" in request.params:
return {}
return super().update_headers(request, response) What do you think? 😄 I'd be more than happy to implement and PR for anything that comes out of this discussion 👍 |
@SteadBytes |
We're having a bit of trouble with an heuristic. The fact is, Heuristic classes get the raw response, (a.k.a the
requests.packages.urllib3.response.HTTPResponse
), which does not contain any information about the request (for example, URL ...).If we look at the parent's
build_response(...)
method, we see it has both raw request and response (cache_response method takes both).Is there any reason (other than BC, obviously) why the heuristic only gets then response, and not the request ?
The text was updated successfully, but these errors were encountered: