{"id":13592317,"url":"https://github.com/zero3301/pyhttpx","last_synced_at":"2025-04-08T23:31:58.196Z","repository":{"id":43025687,"uuid":"510936089","full_name":"zero3301/pyhttpx","owner":"zero3301","description":"A network library based on socket development","archived":false,"fork":false,"pushed_at":"2023-09-14T01:58:00.000Z","size":408,"stargazers_count":244,"open_issues_count":10,"forks_count":56,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-08-02T16:44:37.851Z","etag":null,"topics":["http1","http2","ja3","socket","tls12","tls13"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zero3301.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-07-06T00:34:01.000Z","updated_at":"2024-07-30T21:45:27.000Z","dependencies_parsed_at":"2024-01-14T04:39:46.314Z","dependency_job_id":"742d27db-767a-4100-9a0e-3260bacf0c5a","html_url":"https://github.com/zero3301/pyhttpx","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"3d50b4529cd0545d92030b3bf7071608829f08f2"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero3301%2Fpyhttpx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero3301%2Fpyhttpx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero3301%2Fpyhttpx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zero3301%2Fpyhttpx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zero3301","download_url":"https://codeload.github.com/zero3301/pyhttpx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223346662,"owners_count":17130477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http1","http2","ja3","socket","tls12","tls13"],"created_at":"2024-08-01T16:01:07.995Z","updated_at":"2024-11-06T13:30:52.540Z","avatar_url":"https://github.com/zero3301.png","language":"Python","readme":"# Pyhttpx\n基于socket开发的一个网络库,供研究https/tls参考\n如果你用过requests,它将会变得非常容易\n\n# 版本协议支持\n- tls1.2/tls1.3\n- h1/h2\n\nPyPI:\n```\n$ python -m pip install --upgrade pip\n$ python -m pip install pyhttpx\n```\n\n**安装依赖**\n\nrequirement.txt\n\n```\ncryptography==36.0.1\nrsa==4.8\npyOpenSSL==21.0.0\n\nbrotli==1.0.9\nhpack==4.0.0\n```\n\n\n\n\n## GET\n```\n\u003e\u003e\u003e import pyhttpx\n\u003e\u003e\u003e sess = pyhttpx.HttpSession()\n\u003e\u003e\u003e r = sess.get('https://httpbin.org/get',headers={'User-Agent':'3301'},cookies={'k':'3301')\n\u003e\u003e\u003e r.status_code\n200\n\u003e\u003e\u003e r.encoding\n'utf-8'\n\u003e\u003e\u003e r.text\n'{\\n  \"args\": {}, ...\n\u003e\u003e\u003e r.json\n{'args': {},...\n\n```\n##### 如果你想知道原生http报文是否达到预期,你可以这样\n```\n\u003e\u003e\u003e r.request.raw\nb'GET /get HTTP/1.1\\r\\nHost: httpbin.org ...\n```\n\n## POST\n```\n\u003e\u003e\u003e r = sess.post('https://httpbin.org/get',data={})\n```\n\n## HTTP PROXY\n```\n\u003e\u003e\u003e proxies = {'https': 'http://username:password@host:port'}\n\u003e\u003e\u003e r = sess.post('https://httpbin.org/get',proxies=proxies)\n```\n\n## ALLOW_REDIRECTS\n\n  ```\n\u003e\u003e\u003e r = sess.post('https://httpbin.org/get',allow_redirects=True)\n```  \n\n\n\n# 支持ssl上下文\n\n如果数据是空字符,表示收到fin,服务器断开连接\n\n```\n\u003e\u003e\u003efrom pyhttpx.layers.tls.pyssl import SSLContext,PROTOCOL_TLSv1_2\n\u003e\u003e\u003eimport socket\n\u003e\u003e\u003eaddres = ('httpbin.org', 443)\n\u003e\u003e\u003econtext = SSLContext(PROTOCOL_TLSv1_2, http2=False)\n\u003e\u003e\u003esock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)\n\u003e\u003e\u003essock = context.wrap_socket(sock, server_hostname=addres[0])\n\u003e\u003e\u003essock.connect(addres)\n\u003e\u003e\u003em = 'GET / HTTP/1.1\\r\\nHost: %s\\r\\n\\r\\n' % addres[0]\n\u003e\u003e\u003essock.sendall(m.encode())\n\u003e\u003e\u003er = ssock.recv()\nb'HTTP/1.0 200 OK\\r\\n'...\n```\n\n# websocket\n\n    参考文档tests/test_websockt.py\n    \n\n\n# tls密码套件支持\n- TLS13_AES_128_GCM_SHA256(0X1301)\n- TLS13_AES_256_GCM_SHA384(0X1302)\n- TLS13_CHACHA20_POLY1305_SHA256(0X1303)\n- ECDHE_WITH_AES_128_GCM\n- ECDHE_WITH_AES_256_GCM\n- ECDHE_WITH_CHACHA20_POLY1305_SHA256\n- RSA_WITH_AES_128_GCM\n- RSA_WITH_AES_256_GCM\n- RSA_WITH_AES_128_CBC\n- RSA_WITH_AES_256_CBC\n- ECDHE_WITH_AES_128_CBC\n- ECDHE_WITH_AES_256_CBC\n\n\n### 附录tls相关资料\n\n   [tls1.2](https://www.rfc-editor.org/rfc/rfc5246.html)  \n   [tls1.3](https://www.rfc-editor.org/rfc/rfc8446.html)\n \n### end\n\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzero3301%2Fpyhttpx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzero3301%2Fpyhttpx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzero3301%2Fpyhttpx/lists"}