2017-04-21 70 views
0

我使用超薄框架2 etag()獲取緩存數據,所有工作正常,我得到與郵遞員或任何其他客戶端緩存中的數據,但我得到HTTP 200 OK響應在其餘的客戶端,但因爲所有的時間應該是HTTP 304當數據來自緩存修身框架2 - 沒有得到HTTP 304代碼ETAG()

下面

是我苗條API:

$app->get('/getNew', function() use ($app){ 
    $app->etag('uniqueEtag12'); 
    echo "I am updated one"; 
    }); 

我沒有任何想法,爲什麼我每次我得到作爲我得到的響應緩存數據,下面剩下的客戶端響應代碼是我的休息客戶端的響應單元

enter image description here

爲什麼這個狀態代碼總是200 OK爲什麼我沒有得到狀態碼304請幫助我

回答

0

etag()方法做兩兩件事:

  1. ETag頭添加到響應
  2. 發送304個狀態響應,如果客戶端發送一個If-None-Match頭與價值uniqueEtag12

因此,我認爲你的請求不包括If-None-Match頭。

示例代碼:

的index.php:

<?php 
require 'vendor/autoload.php'; 

$app = new \Slim\Slim(); 

$app->get('/hello', function() use ($app) { 
    $app->etag('1234'); 
    echo "Hello world on " . date("Y-m-d H:i:s"); 
}); 


$app->run(); 

試驗使用捲曲。

沒有If-None-Match頭: $捲曲-i http://localhost:8888/hello

HTTP/1.1 200 OK 
Host: localhost:8888 
Connection: close 
X-Powered-By: PHP/7.0.15 
Content-type: text/html;charset=UTF-8 
Etag: "1234" 

Hello world on 2017-05-04 07:12:40 

隨着If-None-Match頭:

$ curl -i http://localhost:8888/hello -H 'If-None-Match: "1234"' 
HTTP/1.1 304 Not Modified 
Host: localhost:8888 
Connection: close 
X-Powered-By: PHP/7.0.15 
Etag: "1234" 
+0

,但我得到的緩存值 –

+0

是否有'如果無 - Match'頭在HTTP請求中? –

+0

不,我不認爲 –