Skip to content

ATS will send image/webp content to browsers that don't support it #7099

Closed

Description

@bryancall

If a browser that support webp makes a requests through ATS and the origin responds with Content-Type: image/webp that is cacheable ATS will cache the content. If a browser that doesn't support webp, like Safari, then makes a request ATS will serve back the image/webp response. This is because browser's send image/* and / in their Accept: header.

Request from Safari that doesn't support webp:

+++++++++ Incoming Request +++++++++
-- State Machine Id: 0
GET http:///eyJrZXkiOiJ1cGxvYWRzL21lZGl1bS9hc3NldC8xODE4L3Rlc2xhX3dpdGhfYV9yb3NlX29uX3RvcF9vZl9pdC5qcGciLCJidWNrZXQiOiJvc2xvLXByb2R1Y3Rpb24iLCJlZGl0cyI6eyJyZXNpemUiOnsid2lkdGgiOjcwMCwiaGVpZ2h0IjpudWxsfX19 HTTP/1.1
Host: 192.168.1.10:8080
Connection: keep-alive
Accept: image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15
Accept-Language: en-us
Referer: http://192.168.1.10:81/safari.html
Accept-Encoding: gzip, deflate

Activity

  1. self-assigned this
    on Aug 10, 2020
  2. ywkaras commented on Aug 11, 2020

    @ywkaras

    @SolidWallOfCode can txnbox match on Safari in User-Agent and change image/* in Accept to a comma separated list like image/jpeg, image/gif, etc (with any q value used with image/*)? Would that fix this problem?

  3. bryancall commented on Aug 11, 2020

    @bryancall
    ContributorAuthor

    @ywkaras It won't work since the origin doesn't recognize q values and will send back image/webp again, since it has image/webp in the accept header.

    It would however work if image/webp;q=0 is added before doing an ATS cache look up and then removed before going to the origin. I think we should just special case image/webp for now and remove it later in a few years. I have an internal PR up that has that type of logic.

    Example of the origin sending back content-type: image/webp with Accept: image/webp;q=0 in the request:

    $ curl -D - -o /dev/null -s -H 'Accept: image/webp;q=0,image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5' https://dlp31coh2a67q.cloudfront.net/eyJrZXkiOiJ1cGxvYWRzL21lZGl1bS9hc3NldC8xODE4L3Rlc2xhX3dpdGhfYV9yb3NlX29uX3RvcF9vZl9pdC5qcGciLCJidWNrZXQiOiJvc2xvLXByb2R1Y3Rpb24iLCJlZGl0cyI6eyJyZXNpemUiOnsid2lkdGgiOjcwMCwiaGVpZ2h0IjpudWxsfX19
    HTTP/2 200
    content-type: image/webp
    content-length: 18472
    date: Tue, 11 Aug 2020 17:54:50 GMT
    x-amzn-requestid: 70f95e04-b159-45e2-9c38-f4ede3d38153
    last-modified: Wed, 22 Jul 2020 21:31:31 GMT
    access-control-allow-origin: *
    access-control-allow-headers: Content-Type, Authorization
    x-amz-apigw-id: RHc4sFKFiYcF2pg=
    cache-control: max-age=31536000,public
    access-control-allow-methods: GET
    x-amzn-trace-id: Root=1-5f32db6a-2865172535c54d6d87203e86;Sampled=0
    access-control-allow-credentials: true
    x-cache: Hit from cloudfront
    via: 1.1 7eb3b782ab09047ce0d11ee03763894c.cloudfront.net (CloudFront)
    x-amz-cf-pop: SEA19-C2
    x-amz-cf-id: 1HPCddByV7clafDzYTNPOxMcgpn_LM-ajvqyQfGh4jVwHnhZ-NvCuw==
    age: 2
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions