mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
docs: clarify reverse proxy compatibility behavior
Document BufferPool usage and explain why trailer fallback and disconnect compatibility logic intentionally mirror the standard library reverse proxy. Add a regression test covering unannounced trailer forwarding so that proxy trailer behavior stays aligned with Go's semantics.
This commit is contained in:
parent
764a764720
commit
e4ca20e848
3 changed files with 80 additions and 0 deletions
|
|
@ -187,6 +187,43 @@ func TestReverseProxyCustomErrorHandler(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestReverseProxyUnannouncedTrailerForwarding(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set(http.TrailerPrefix+"X-Unannounced-Trailer", "later")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = io.WriteString(w, "streamed")
|
||||
}))
|
||||
defer backend.Close()
|
||||
|
||||
target, err := url.Parse(backend.URL)
|
||||
if err != nil {
|
||||
t.Fatalf("parse target: %v", err)
|
||||
}
|
||||
|
||||
engine := New()
|
||||
engine.GET("/trailers", ReverseProxy(ReverseProxyConfig{Target: target}))
|
||||
|
||||
rr := PerformRequest(engine, http.MethodGet, "/trailers", nil, nil)
|
||||
resp := rr.Result()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("read body: %v", err)
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("unexpected status: %d", resp.StatusCode)
|
||||
}
|
||||
if string(body) != "streamed" {
|
||||
t.Fatalf("unexpected body: %q", string(body))
|
||||
}
|
||||
if got := resp.Trailer.Get("X-Unannounced-Trailer"); got != "later" {
|
||||
t.Fatalf("unexpected unannounced trailer: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReverseProxyProtocolUpgrade(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue