0

I'm trying to configure an HAProxy backend to work with Google-CDN I see that I always get to the HAProxy backend and the cache is always MISS

This is google-cdn requests regarding headers: https://cloud.google.com/cdn/docs/caching#cacheability

and this is my HAProxy backend configurations (I've tried multiple sets of headers configuration, but never got an HIT):

    http-response set-header Cache-Control public;max-age=31536000
    http-response set-header Content-Length 260113322
#    http-request add-header Cache-Control public;max-age=31533000
#    http-request add-header Content-Length 26012101001

when I'm requesting the object in the browser these are the req\res headers:

Response Headers

alt-svc: clear
cache-control: public;max-age=31536000
content-length: 260113322
content-type: application/javascript; charset=utf-8
date: Thu, 05 Sep 2019 07:56:59 GMT
etag: W/"47e80-NwQR7oXLIZF+J1AAVu9L0mv54I4"
status: 200
vary: Accept-Encoding
via: 1.1 google

Request Headers

:authority: sapix-stg.example.net
:method: GET
:path: /bb/client/SX1234/main.js
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
pragma: no-cache
sec-fetch-mode: navigate
sec-fetch-site: none
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36

Thanks

2 Answers2

1

Your Cache-Control reaponse header is malformed. The values are separared with a comma (and optional whitespace included by convention) -- not a semicolon.

http-response set-header Cache-Control "public, max-age=31536000"

The quotes are absorbed by the HAProxy parser. Also valid:

(no space)

http-response set-header Cache-Control public,max-age=31536000

(space escaped)

http-response set-header Cache-Control public,\ max-age=31536000

There should normally be no need to add Content-Length in the proxy. If your origin server isn't automatically setting either Content-Length or Transfer-Encoding in the response, then your server should be fixed, upgraded, or replaced.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
0

It might be because your response contains "Vary" header. HAPoxy says that they don't cache that type of responses.

bahruz
  • 351
  • 3
  • 2