BaseHTTPRequestHandler.parse_request() loses client-provided information
未關閉
還沒有人認領這個 Issue。
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 平均合併
- 1 天 9 小時
- 30 天內合併 PR
- 558
描述
Bug report
The fix for https://github.com/python/cpython/issues/87389 prevents servers from handling request paths with multiple leading slashes.
For example, one might have a simple server that just reflects the request path:
from http.server import *
class MyHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(self.path.encode('latin1'))
with ThreadingHTTPServer(('127.0.0.1', 8000), MyHTTPRequestHandler) as server:
server.serve_forever()
Previously, this would faithfully mirror the request path from the client:
$ curl -v http://localhost:8000//test
* Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET //test HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.82.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.8.13
< Date: Mon, 07 Nov 2022 21:51:19 GMT
<
* Closing connection 0
//test
But now it mangles it:
$ curl -v http://localhost:8000//test
* Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET //test HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.82.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.11.0
< Date: Mon, 07 Nov 2022 21:51:30 GMT
<
* Closing connection 0
/test
This impacts any servers that subclass BaseHTTPRequestHandler, such as eventlet's WSGI server.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 BaseHTTPRequestHandler.parse_request() 開始,將其目前對 //test 請求的處理與報告中顯示的行為進行比較。追蹤與 issue 87389 相關的變更,並找出用戶端提供的路徑在哪裡遭到修改。當像範例伺服器這樣的子類別能夠接收原始的開頭斜線,且不造成請求驗證回歸時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend-api-design, networking
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100