@@ -192,17 +192,23 @@ func (r *Service) AsIs(resp http.ResponseWriter, req *http.Request) {
192192
193193 Log .Printf ("Requested image %s as is\n " , imgUrl )
194194
195- result , err := r .Loader .Load (imgUrl , req .Context ())
195+ var proxyHeaders = make (http.Header )
196+ accept := req .Header .Get ("Accept" )
197+ if len (accept ) > 0 {
198+ proxyHeaders .Add ("Accept" , accept )
199+ }
200+ acceptEncoding := req .Header .Get ("Accept-Encoding" )
201+ if len (acceptEncoding ) > 0 {
202+ proxyHeaders .Add ("Accept-Encoding" , acceptEncoding )
203+ }
204+
205+ result , err := r .Loader .Load (imgUrl , NewContextWithHeaders (req .Context (), & proxyHeaders ))
196206
197207 if err != nil {
198208 sendError (resp , err )
199209 return
200210 }
201211
202- if len (result .MimeType ) > 0 {
203- resp .Header ().Add ("Content-Type" , result .MimeType )
204- }
205-
206212 r .execOp (& Command {
207213 Config : & TransformationConfig {
208214 Src : & Image {
@@ -239,11 +245,15 @@ func (r *Service) getQueue() *Queue {
239245
240246// Adds Content-Length and Cache-Control headers
241247func addHeaders (resp http.ResponseWriter , image * Image ) {
248+ headers := resp .Header ()
242249 if len (image .MimeType ) != 0 {
243- resp .Header ().Add ("Content-Type" , image .MimeType )
250+ headers .Add ("Content-Type" , image .MimeType )
251+ }
252+ if len (image .ContentEncoding ) != 0 {
253+ headers .Add ("Content-Encoding" , image .ContentEncoding )
244254 }
245- resp . Header () .Add ("Content-Length" , strconv .Itoa (len (image .Data )))
246- resp . Header () .Add ("Cache-Control" , fmt .Sprintf ("public, max-age=%d" , CacheTTL ))
255+ headers .Add ("Content-Length" , strconv .Itoa (len (image .Data )))
256+ headers .Add ("Cache-Control" , fmt .Sprintf ("public, max-age=%d" , CacheTTL ))
247257}
248258
249259func getQueryParam (url * url.URL , name string ) (string , bool ) {
@@ -391,3 +401,18 @@ func sendError(resp http.ResponseWriter, err error) {
391401 }
392402 }
393403}
404+
405+ type headersKey int
406+
407+ func NewContextWithHeaders (ctx context.Context , headers * http.Header ) context.Context {
408+ return context .WithValue (ctx , headersKey (0 ), headers )
409+ }
410+
411+ func HeaderFromContext (ctx context.Context ) (* http.Header , bool ) {
412+ if ctx == nil {
413+ return nil , false
414+ }
415+
416+ header , ok := ctx .Value (headersKey (0 )).(* http.Header )
417+ return header , ok
418+ }
0 commit comments