Skip to content

victorloo/http-request-lab

Repository files navigation

HTTP Request Lab

一鍵啟動的 HTTP 請求比較實驗室:觀察不同語言 / Library 發出的原始 HTTP 電文差異。

目的

在實務中,不同 HTTP library 的預設行為差異可能導致問題,例如:

  • 某些 library 預設使用 Transfer-Encoding: chunked,而 server 端可能不支援
  • Header 的大小寫、排列順序、自動附加的 header 各不相同
  • TLS handshake 使用的版本與加密套件也有差異
  • HTTP/1.1 與 HTTP/2 的傳輸機制根本不同(chunked vs frame)

這個專案提供一個統一的測試環境,讓開發者可以實際觀察並比較這些差異。

截圖

Log Viewer — Light 模式(繁體中文)

Light Mode

Log Viewer — Dark 模式(繁體中文)

Dark Mode

Log Viewer — English

English

Header 表格模式 — 一覽各 library 的 HTTP header 差異

Table Mode

架構

                                 ┌──────────────┐
                                 │  Vue.js App  │
                                 │  (Viewer)    │
                                 │  Port: 5173  │
                                 └──────┬───────┘
                                        │ /api/logs
                                        ▼
Client ──→ mitmproxy ──→ Server (Go)    ← 同時提供 API 給前端
Client ──→ Server (Go)
  • Server: Go 實作,記錄原始 TCP bytes + parsed HTTP 內容,同時提供 Log API
  • Viewer: Vue.js 前端,篩選與檢視 log 的 Web UI
  • Proxy: mitmproxy,攔截並記錄完整的 protocol 層級資訊
  • Clients: 各語言 / Library 的 HTTP 請求實作

測試的語言與 Library

語言 Libraries
Node.js built-in http, axios, node-fetch, got, undici
Java HttpURLConnection, Java 11+ HttpClient, OkHttp
Spring RestTemplate (JDK / Apache HttpClient), WebClient
Python built-in urllib, requests, httpx, urllib3, aiohttp
Go net/http, resty
C# HttpClient, RestSharp

使用方式

# 1. 產生自簽憑證
./certs/generate-certs.sh

# 2. 建立環境設定與測試資料
cp .env.example .env
cp test-data.example.json test-data.json

# 3. 編輯 test-data.json,填入你要測試的資料
#    (.env 通常不需要修改,除非有特殊的 port 需求)

# 4. 啟動所有服務
docker compose up

# 5. 查看結果
#    Log Viewer:     http://localhost:5173
#    mitmproxy UI:   http://localhost:8190
#    Raw log 檔案:   ls logs/

一鍵測試

# 執行全部 client
./scripts/run-all.sh

# 只執行特定語言
./scripts/run-all.sh python
./scripts/run-all.sh java spring

# 產生比較報告
./scripts/diff-report.sh

專案結構

http-request-lab/
├── server/              # Go server(Raw TCP + Parsed HTTP logger + Log API)
├── viewer/              # Vue.js 前端(Log Viewer Web UI)
├── clients/
│   ├── python/          # urllib, requests, httpx, urllib3, aiohttp
│   ├── java/            # HttpURLConnection, HttpClient, OkHttp
│   ├── spring/          # RestTemplate (JDK/Apache), WebClient
│   ├── go/              # net/http, resty
│   ├── nodejs/          # http, axios, node-fetch, got, undici
│   └── csharp/          # HttpClient, RestSharp
├── scripts/             # run-all.sh, diff-report.sh
├── certs/               # TLS 自簽憑證產生 script
├── logs/                # Server 記錄的 log 檔案(gitignore)
├── docs/                # 測試結果報告
├── .env.example         # 環境變數範本
└── test-data.example.json  # 測試資料範本

文件

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors