...
项目描述
HTTPCore
功能支持
- HTTP/2和- HTTP/1.1支持。
- async/- await支持非阻塞HTTP请求。
- 默认严格超时。
- 完全类型注解。
- 100%测试覆盖率。
以及所有requests标准功能...
- 国际域名和URL
- Keep-Alive & 连接池
- 带有Cookie持久性的会话
- 浏览器式SSL验证
- 基本/摘要身份验证 TODO - 我们已经有了基本,但没有摘要。
- 优雅的键/值Cookie
- 自动解压缩
- 自动内容解码
- Unicode响应体
- 多部分文件上传 TODO - 请求内容目前支持URL编码数据、JSON、字节或异步字节迭代器。
- HTTP(S)代理支持 TODO
- 连接超时
- 流式下载
- .netrc支持 TODO
- 分块请求
用法
发起请求
>>> import httpcore
>>> client = httpcore.Client()
>>> response = client.get('https://example.com')
>>> response.status_code
<HTTPStatus.OK: 200>
>>> response.protocol
'HTTP/2'
>>> response.text
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'
或者,异步请求
注意: 使用ipython在控制台尝试此操作,因为它支持await。
>>> import httpcore
>>> client = httpcore.AsyncClient()
>>> response = await client.get('https://example.com')
>>> response.status_code
<StatusCode.OK: 200>
>>> response.protocol
'HTTP/2'
>>> response.text
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'
依赖关系
- h2- HTTP/2支持。
- h11- HTTP/1.1支持。
- certifi- SSL证书。
- chardet- 响应编码的回退自动检测。
- idna- 国际化域名支持。
- rfc3986- URL解析 & 正规化。
- brotlipy- 对 "brotli" 压缩响应的解码。 (可选)
此工作大部分遵循的 API 布局归功于 requests,以及为底层网络细节提供的许多设计灵感的 urllib3。
API 参考
客户端
一个具有连接池、重定向、Cookie 持久性等功能的 HTTP 客户端。
>>> client = Client()
>>> response = client.get('https://example.org')
- def __init__([auth], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [dispatch])
- def .request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])
- def .prepare_request(request)
- def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout])
- def .close()
响应
一个 HTTP 响应。
- def __init__(...)
- .status_code- int (通常是一个- StatusCodeIntEnum.)
- .reason_phrase- str
- .protocol-- "HTTP/2"或- "HTTP/1.1"
- .url- URL
- .headers- Headers
- .content- bytes
- .text- str
- .encoding- str
- .is_redirect- bool
- .request- Request
- .cookies- Cookies
- .history- List[Response]
- def .raise_for_status()- None
- def .json()- Any
- def .read()- bytes
- def .stream()- bytes iterator
- def .raw()- bytes iterator
- def .close()- None
- def .next()- Response
请求
一个 HTTP 请求。可以显式构建以获得对通过网络发送内容的更多控制。
>>> request = Request("GET", "https://example.org", headers={'host': 'example.org'})
>>> response = client.send(request)
- def __init__(method, url, [params], [data], [json], [headers], [cookies])
- .method- str
- .url- URL
- .content- byte 或 byte async iterator
- .headers- Headers
- .cookies- Cookies
URL
一个规范化、支持 IDNA 的 URL。
>>> url = URL("https://example.org/")
>>> url.host
'example.org'
- def __init__(url, allow_relative=False, params=None)
- .scheme- str
- .authority- str
- .host- str
- .port- int
- .path- str
- .query- str
- .full_path- str
- .fragment- str
- .is_ssl- bool
- .origin- Origin
- .is_absolute_url- bool
- .is_relative_url- bool
- def .copy_with([scheme], [authority], [path], [query], [fragment])- URL
- def .resolve_with(url)- URL
源
一个规范化、支持 IDNA 的方案/主机/端口信息集。
>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')
True
- def __init__(url)
- .is_ssl- bool
- .host- str
- .port- int
头部
一个不区分大小写的多字典。
>>> headers = Headers({'Content-Type': 'application/json'})
>>> headers['content-type']
'application/json'
- def __init__(self, headers)
Cookie
一个类似字典的 Cookie 存储库。
>>> cookies = Cookies()
>>> cookies.set("name", "value", domain="example.org")
- def __init__(cookies: [dict, Cookies, CookieJar])
- .jar- CookieJar
- def extract_cookies(response)
- def set_cookie_header(request)
- def set(name, value, [domain], [path])
- def get(name, [domain], [path])
- def delete(name, [domain], [path])
- def clear([domain], [path])
- 标准可变映射接口
备选后端
AsyncClient
异步客户端。
TrioClient
待办事项
堆栈
堆栈中有两层主要结构。客户端处理重定向、cookie持久性(待办事项)和身份验证(待办事项)。调度器处理发送实际请求和获取响应。
- Client- 重定向、身份验证、cookie等。
- ConnectionPool(Dispatcher)- 连接池和保持活动状态。- HTTPConnection- 单个连接。- HTTP11Connection- 单个HTTP/1.1连接。
- HTTP2Connection- 单个HTTP/2连接,具有多个流。
 
 
项目详情
    
       关闭
    
      
        
    
    
  
encode-0.0.0.tar.gz 的散列
| 算法 | 散列摘要 | |
|---|---|---|
| SHA256 | bb79966ae0274363551cd6454537cddb13ad6347190d662e8cda2860b12b4f5f | |
| MD5 | 35e61d335e6aeb55fcdbd22dc33d2e59 | |
| BLAKE2b-256 | b396c3433d817f31e1bd93f4b07bc970b95e7e9e12ac3a6e15d03c98efc26324 |