@@ -45,7 +45,7 @@ import (
45
45
// Cache-Control does not include "no-store", and does include "immutable".
46
46
//
47
47
// In addition, a successful response that is not immutable and specifies a
48
- // max-age will be cached temporarily in-memory, up to the maximum of 1h .
48
+ // max-age will be cached temporarily in-memory.
49
49
//
50
50
// # Cache Format
51
51
//
@@ -67,10 +67,7 @@ import (
67
67
// the storage key of the cache object.
68
68
type Server struct {
69
69
// Targets is the list of hosts for which the proxy should forward requests.
70
- //
71
- // Each target is either a hostname ("host.domain.com"), which matches
72
- // hostnames exactly, or a pattern of the form "*.domain.com" which matches
73
- // hostnames like "domain.com" and "something.domain.com".
70
+ // Host names should be fully-qualified ("host.example.com").
74
71
Targets []string
75
72
76
73
// Local is the path of a local cache directory where responses are cached.
@@ -149,8 +146,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
149
146
s .reqReceived .Add (1 )
150
147
151
148
// Check whether this request is to a target we are permitted to proxy for.
152
- if ! hostMatchesTarget (r .URL . Host , s .Targets ) {
153
- s .logf ("reject proxy request for non-target %q" , r .URL )
149
+ if ! hostMatchesTarget (r .Host , s .Targets ) {
150
+ s .logf ("reject proxy request for non-target %q" , r .Host )
154
151
http .Error (w , http .StatusText (http .StatusBadGateway ), http .StatusBadGateway )
155
152
return
156
153
}
@@ -273,16 +270,7 @@ func (s *Server) logf(msg string, args ...any) {
273
270
}
274
271
275
272
func hostMatchesTarget (host string , targets []string ) bool {
276
- return slices .ContainsFunc (targets , func (s string ) bool {
277
- if s == host {
278
- return true
279
- } else if tail , ok := strings .CutPrefix (s , "*" ); ok {
280
- if strings .HasSuffix (host , tail ) || host == strings .TrimPrefix (tail , "." ) {
281
- return true
282
- }
283
- }
284
- return false
285
- })
273
+ return slices .Contains (targets , host )
286
274
}
287
275
288
276
// canCacheRequest reports whether r is a request whose response can be cached.
0 commit comments