MCPcopy
hub / github.com/willnorris/imageproxy / NewProxy

Function NewProxy

imageproxy.go:109–140  ·  view source on GitHub ↗

NewProxy constructs a new proxy. The provided http RoundTripper will be used to fetch remote URLs. If nil is provided, http.DefaultTransport will be used.

(transport http.RoundTripper, cache Cache)

Source from the content-addressed store, hash-verified

107// used to fetch remote URLs. If nil is provided, http.DefaultTransport will
108// be used.
109func NewProxy(transport http.RoundTripper, cache Cache) *Proxy {
110 if transport == nil {
111 transport, _ = aia.NewTransport()
112 }
113 if cache == nil {
114 cache = NopCache
115 }
116
117 proxy := &Proxy{
118 Cache: cache,
119 }
120
121 client := new(http.Client)
122 client.Transport = &httpcache.Transport{
123 Transport: &TransformingTransport{
124 Transport: transport,
125 CachingClient: client,
126 log: func(format string, v ...any) {
127 if proxy.Verbose {
128 proxy.logf(format, v...)
129 }
130 },
131 updateCacheHeaders: proxy.updateCacheHeaders,
132 },
133 Cache: cache,
134 MarkCachedResponses: true,
135 }
136
137 proxy.Client = client
138
139 return proxy
140}
141
142// updateCacheHeaders updates the cache-control headers in the provided headers.
143//

Callers 3

mainFunction · 0.92
ProvisionMethod · 0.92
TestAllowedFunction · 0.85

Calls 1

logfMethod · 0.95

Tested by 1

TestAllowedFunction · 0.68