蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

HTTP 响应头:完整字段、缓存与历史机制:核心实验

PYTHONWindows回环;Python3.12;临时TLS证书;Node HTTP2headers_case.py
headers_case.py9 行
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

请结合实际环境逐项观察。

附件与关联工程包下载

下载课程关联工程包:HTTP

课程关联工程包(登记关联10章) · 含当前章节或实例 · mbskycom202611a517.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习