File: urllib3_chunked_response.py

package info (click to toggle)
python-pook 2.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: python: 3,558; makefile: 13
file content (16 lines) | stat: -rw-r--r-- 374 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import urllib3

import pook

# Mock HTTP traffic only in the given context
with pook.use():
    (
        pook.get("httpbin.org/chunky")
        .reply(200)
        .body(["returned", "as", "chunks"], chunked=True)
    )

    # Intercept request
    http = urllib3.PoolManager()
    r = http.request("GET", "httpbin.org/chunky")
    print("Chunks:", list(r.read_chunked()))