2015-01-27 1 views
1

저는 프랑스 인입니다. 영어로 유감입니다.사용자 컨텍스트가 없습니다. FOSHttpCacheBundle + 바니쉬

내 설정 : 니스 포트 80 아파치의 포트 8080 심포니에 : 2.5.9

나는 X-사용자 상황에 해시 내 응답 헤더를 가질 수 없습니다. 저를 도울 수 있기 때문에 나를 도울 수 있습니까?

config.vcl :

여기에 같은 : I를 제외하고 http://foshttpcache.readthedocs.org/en/latest/varnish-configuration.html#varnish-user-context은 "/ 사용자 상황에 해시"

sub vcl_recv { 

    # Prevent tampering attacks on the hash mechanism 
    if (req.restarts == 0 
     && (req.http.accept ~ "application/vnd.fos.user-context-hash" 
      || req.http.x-user-context-hash 
     ) 
    ) { 
     return (synth(400)); 
    } 

    # Lookup the context hash if there are credentials on the request 
    # Only do this for cacheable requests. Returning a hash lookup discards the request body. 
    # https://www.varnish-cache.org/trac/ticket/652 
    if (req.restarts == 0 
     && (req.http.cookie || req.http.authorization) 
     && (req.method == "GET" || req.method == "HEAD") 
    ) { 
     # Backup accept header, if set 
     if (req.http.accept) { 
      set req.http.x-fos-original-accept = req.http.accept; 
     } 
     set req.http.accept = "application/vnd.fos.user-context-hash"; 

     # Backup original URL 
     set req.http.x-fos-original-url = req.url; 
     set req.url = "/user-context-hash"; 

     # Force the lookup, the backend must tell not to cache or vary on all 
     # headers that are used to build the hash. 
     return (hash); 
    } 

    # Rebuild the original request which now has the hash. 
    if (req.restarts > 0 
     && req.http.accept == "application/vnd.fos.user-context-hash" 
    ) { 
     set req.url = req.http.x-fos-original-url; 
     unset req.http.x-fos-original-url; 
     if (req.http.x-fos-original-accept) { 
      set req.http.accept = req.http.x-fos-original-accept; 
      unset req.http.x-fos-original-accept; 
     } else { 
      # If accept header was not set in original request, remove the header here. 
      unset req.http.accept; 
     } 

     # Force the lookup, the backend must tell not to cache or vary on the 
     # user hash to properly separate cached data. 

     return (hash); 
    } 
} 

sub vcl_backend_response { 
    if (bereq.http.accept ~ "application/vnd.fos.user-context-hash" 
     && beresp.status >= 500 
    ) { 
     return (abandon); 
    } 
} 

sub vcl_deliver { 
    # On receiving the hash response, copy the hash header to the original 
    # request and restart. 
    if (req.restarts == 0 
     && resp.http.content-type ~ "application/vnd.fos.user-context-hash" 
    ) { 
     set req.http.x-user-context-hash = resp.http.x-user-context-hash; 

     return (restart); 
    } 

    # If we get here, this is a real response that gets sent to the client. 

    # Remove the vary on context user hash, this is nothing public. Keep all 
    # other vary headers. 
    set resp.http.Vary = regsub(resp.http.Vary, "(?i),? *x-user-context-hash *", ""); 
    set resp.http.Vary = regsub(resp.http.Vary, "^, *", ""); 
    if (resp.http.Vary == "") { 
     unset resp.http.Vary; 
    } 

    # Sanity check to prevent ever exposing the hash to a client. 
    unset resp.http.x-user-context-hash; 
} 

config_cache.yml에 의해 "/user_context_hash.php"를 변경

fos_http_cache: 
    user_context: 
     enabled: true 
     role_provider: true 
    cache_control: 
     defaults: 
      overwrite: true 
     rules: 
      - 
       match: 
        path: ^/ 
       headers: 
        overwrite: true 
        cache_control: 
         public: true 
         max_age: 60000 
         s_maxage: 56000 
        last_modified: "-1 hour" 
        vary: [Accept-Encoding, Accept-Language] 

routing_cache.yml :

user_context_hash: 
    path: /user-context-hash 

app_dev.php :

/*require_once __DIR__.'/../app/AppCache.php';*/ 
/*$kernel = new AppCache($kernel);*/ 

composer.json :

"friendsofsymfony/http-cache-bundle": "1.2.0" 

Réponse 헤더 :

headers 
Date: Mon, 26 Jan 2015 20:11:48 GMT 
Server: Apache/2.2.22 (Debian) 
X-Powered-By: PHP/5.4.35-0+deb7u2 
Cache-Control: max-age=60000, public, s-maxage=56000 
X-Cache-Debug: 1 
Last-Modified: Mon, 26 Jan 2015 19:11:48 GMT 
x-url:/
x-host: datav1.XXX.com 
X-Varnish: 229440 229433 
Age: 84 
Via: 1.1 varnish-v4 
Vary: Accept-Encoding,Accept-Language 
Content-Encoding: gzip 
Content-Type: text/html; charset=UTF-8 
Accept-Ranges: bytes 

THX!

답변

0

바니시는 번들이 제공하는 x-user-context-hash 기능을 처리하기 위해 내부적으로 여러 가지 하위 요청 ("재시작"이라고 함)을 만듭니다.

vcl_deliver의 마지막 줄에서 알 수 있듯이 해당 헤더의 설정이 해제되어 있으므로 응답 헤더간에 노출되지 않습니다. 프로덕션 작업을 수행하지 않는 것이 좋지만 개발하는 동안 해당 행을 주석 처리 할 수 ​​있습니다.