Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cache-Control" Header in Web()->request(); not working #908

Closed
exodus4d opened this issue Jan 24, 2016 · 4 comments
Closed

"Cache-Control" Header in Web()->request(); not working #908

exodus4d opened this issue Jan 24, 2016 · 4 comments

Comments

@exodus4d
Copy link

I use \Web::instance()->request(); to perform third-party API calls. The response headers of my cURL request look like this:

 [headers] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Server: nginx/1.2.0
            [2] => Content-Type: application/vnd.ccp.eve.Api-v3+json; charset=utf-8
            [3] => Transfer-Encoding: chunked
            [4] => Connection: close
            [5] => Vary: Accept-Encoding
            [6] => Access-Control-Max-Age: 1728000
            [7] => Access-Control-Expose-Header: CONTENT-TYPE
            [8] => Cache-Control: private, max-age=60
            [9] => Access-Control-Allow-Origin: *
            [10] => X-Cache-Status: HIT
            [11] => Date: Sun, 24 Jan 2016 16:10:26 GMT
            [12] => Access-Control-Allow-Methods: GET, PUT, POST, DELETE, HEAD, OPTIONS
            [13] => Access-Control: allow <*>
            [14] => Access-Control-Allow-Headers: AUTHORIZATION, X-REQUESTED-WITH, CONTENT-TYPE, ACCEPT
            [15] => Content-Encoding: gzip
        )

I would expect the response should be cached automatically because of its Cache-Control header (Cache-Control: private, max-age=60).

Unfortunately the preg_match() which checks this header, does not take care of the "private" part L537. Therefore the "max-age" of "60" is not found.

I think we could adjust the regex a bit to take care of it.

Reference: Specification 14.9 Cache-Control

@KOTRET
Copy link
Collaborator

KOTRET commented Jan 24, 2016

take care here, the order of the params is not limited to this version, it could be
Cache-Control: max-age=60, private

    Cache-Control   = "Cache-Control" ":" 1#cache-directive

    cache-directive = cache-request-directive
         | cache-response-directive

    cache-request-directive =
           "no-cache"
         | "no-store"
         | "max-age" "=" delta-seconds
         | "max-stale" [ "=" delta-seconds ]
         | "min-fresh" "=" delta-seconds
         | "no-transform"
         | "only-if-cached"
         | cache-extension

     cache-response-directive =
           "public"
         | "private" [ "=" <"> 1#field-name <"> ]
         | "no-cache" [ "=" <"> 1#field-name <"> ]
         | "no-store" 
         | "no-transform"
         | "must-revalidate"
         | "proxy-revalidate"
         | "max-age" "=" delta-seconds
         | "s-maxage" "=" delta-seconds
         | cache-extension

    cache-extension = token [ "=" ( token | quoted-string ) ]

@ikkez
Copy link
Collaborator

ikkez commented Apr 23, 2016

should be fixed now at f3-factory/fatfree-core@59075a1

@exodus4d
Copy link
Author

exodus4d commented May 6, 2016

@ikkez thanks for the fix.I have just tested this, works fine!

There is just one point (which is probably a problem from the API a use and not F3). In my case a get multiple Cache-Headers as response:

  • Cache-Control and Access-Control-Max

Is this a common use case, or just a strange implementation of that API? The Access-Control-Max is not treated by F3. This is not a problem for me, I just want to mention that.

Issue can be closed anyways ;)

@exodus4d exodus4d closed this as completed May 6, 2016
@exodus4d
Copy link
Author

exodus4d commented May 6, 2016

I already got an answer:

Access-Control-Max-Ageis how long browsers should cache the access-control (cors) headers. It has nothing to do with the content of the request.
https://www.reddit.com/r/evetech/comments/4i5omq/crest_cache_header_ambiguous/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants