Skip to content

Streaming without "with" like urllib3 #649

Closed

Description

@GunGunGun

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:

import urllib3
p = urllib3.PoolManager()
r = p.urlopen('https://example.com', preload_content=False)
h = r.headers
# Filter h > headers, for example:
if 'google.com' in h.get('Referer'):
    # Abort request
# If h is okay then
d = r.data
# Then send to client

Activity

  1. locked and limited conversation to collaborators on Jan 11, 2023
  2. converted this issue into a discussion #650 on Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions