| 87 | } |
| 88 | |
| 89 | func TestHostPatchHandler(t *testing.T) { |
| 90 | host := "" |
| 91 | rh := HostPatchHandler{ |
| 92 | HostPatch{ |
| 93 | RemovePort: true, |
| 94 | RemoteTrailingDot: true, |
| 95 | }, |
| 96 | http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { host = r.Host }), |
| 97 | } |
| 98 | rh.ServeHTTP(nil, &http.Request{Host: "example.com.:8080"}) |
| 99 | |
| 100 | if host != "example.com" { |
| 101 | t.Errorf("expected example.com, got: %s", host) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func BenchmarkHostPatchCommon(b *testing.B) { |
| 106 | hp := HostPatch{RemovePort: true, RemoteTrailingDot: true, ToLower: true} |