HttpRequest not respecting header codes from requested page
I'm using the HttpRequest class on a proxy to call an API. I have modifications for caching on the API to throw a 304 if the content has not been modified so that the user mak开发者_JS百科ing the request can utilize caching.
The API throws a header:
header('HTTP/1.1 304 Not Modified');
I've confirmed that this is working by inspecting the headers; in firefox a ctrl+shift+r will always return a 200, a ctrl+r after a 200 will always result in the 304. However, on the proxy side the HttpRequest object always returns 200. I've even tried modifying the API so it always throws the 304 no matter what but the proxy still yields 200.
How can I get it to respect the 304 being thrown by the API so I can throw the 304 from the proxy as well?
If your caching logic in the API server is correct, then you should really only get a 304 when sending a conditional request like this:
$last_request = time() - 60;
// should be an actual timestamp of cached data!
$last_date = gmdate("D, d M Y H:i:s T", $last_request);
$request = new HttpRequest($url, $method_type);
$request->setHeaders(array('If-Unmodified-Since' => $last_date));
$request->send();
精彩评论