from client_lib import *
with running() as (server,_):
c=connection(server);r,b=request(c,'GET','/cache');tag=r.getheader('ETag');assert tag==ETAG and r.getheader('Cache-Control')=='no-cache' and r.getheader('Vary')=='Accept-Encoding' and r.getheader('Date')
r,b=request(c,'GET','/cache',headers={'If-None-Match':tag});assert r.status==304 and b==b''
r,b=request(c,'GET','/cache',headers={'Range':'bytes=0-3'});assert r.status==206 and b==BODY[:4] and r.getheader('Content-Range')==f'bytes 0-3/{len(BODY)}'
r,b=request(c,'GET','/gzip');assert r.getheader('Content-Encoding')=='gzip' and gzip.decompress(b)==BODY and int(r.getheader('Content-Length'))==len(b)
r,b=request(c,'GET','/redirect');assert r.status==307 and r.getheader('Location')=='/'
c.close();out(conditional_304=True,range_206=True,gzip_real_bytes=True,redirect_location=True,deprecated_headers_not_emitted=True)
本例需在 Windows回环;Python3.12;临时TLS证书;Node HTTP2 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows回环;Python3.12;临时TLS证书;Node HTTP2
入口文件:projects/http-lab/headers_case.py
预期结果与验证条件观察提示
- 真实304、206、gzip解压及307 Location
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联10章) · 含当前章节或实例 · mbskycom202611a517.zip