Replies: 1 comment
-
So... the You should be able to get the same behaviour, but it'll ensure you've got good guardrails and can't accidentally leave the response in an open state... import httpcore
p = httpcore.ConnectionPool()
with p.stream('GET', 'https://example.com') as r:
h = dict(r.headers)
if 'google.com' in h.get('Referer', ''):
# Abort request
# If h is okay then
r.read()
d = r.content
# Then send to client |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In urllib3, I can use r = pool.urlopen('GET', url, preload_content=False) to stream content, and it's very useful because I can then use r.headers to get only response headers, then use r.data to get content. It seems very hard to do so in httpcore because I need to use with to wrap httpcore.stream('GET', url), but I find it's very limited, for example I have a local transparent web filter proxy, it's better to be able to fetch only response headers, filter/change response headers first, then download content later if response headers is not blocked.
In urllib3 I use:
Beta Was this translation helpful? Give feedback.
All reactions