mirror of
https://github.com/zap-proto/http.git
synced 2026-10-04 03:07:19 +00:00
v0.3.3 renamed this to package zap, and that was wrong twice. Go resolves an unaliased import to the package's own name, so github.com/zap-proto/http should answer to http; and this package IMPORTS zap, the wire format, so naming itself zap put two different things under one word in the same file. An importer that also needs net/http aliases one of them, which is the ordinary convention rather than a reason to invent a name. zap.Version and zap.HeaderSize are that other package and are untouched. Co-authored-by: Hanzo Dev <[email protected]>
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package http
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
// THE HOST REACHES THE CALLEE. It is the only thing telling a callee which of
|
|
// several brands was asked for, and this wire used to drop it: the encoder
|
|
// excluded Host as "frame-owned" while nothing in the frame carried one, and the
|
|
// decoder reconstructed it from the very header the encoder had removed. Every
|
|
// request arrived with an empty Host, invisibly, because a callee that serves
|
|
// one brand never reads it.
|
|
func TestHostSurvivesTheWire(t *testing.T) {
|
|
in := fasthttp.AcquireRequest()
|
|
defer fasthttp.ReleaseRequest(in)
|
|
in.Header.SetMethod(fasthttp.MethodGet)
|
|
in.Header.SetRequestURI("/v1/iam/.well-known/openid-configuration")
|
|
in.Header.SetHost("lux.id")
|
|
|
|
var enc []byte
|
|
enc = appendRequestHeaders(enc, &in.Header, (*trailerSkip)(nil))
|
|
|
|
out := fasthttp.AcquireRequest()
|
|
defer fasthttp.ReleaseRequest(out)
|
|
if err := decodeRequestHeaders(&out.Header, enc); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if got := string(out.Header.Host()); got != "lux.id" {
|
|
t.Fatalf("callee saw Host %q, want \"lux.id\" — a multi-brand callee cannot answer as the brand it was asked as", got)
|
|
}
|
|
}
|