En utilisant PHP comment puis-je tester avec précision qu'un site Web distant prend en charge l'en-tête HTTP "If-Modified-Since". D'après ce que j'ai lu, si le fichier distant que vous avez modifié a été modifié depuis la date spécifiée dans la demande d'en-tête, il doit renvoyer un état 200 OK. S'il n'a pas été modifié, il doit retourner un 304 non modifié.Comment tester pour le support d'en-tête HTTP "If-Modified-Since"
Par conséquent, ma question est, et si le serveur ne prend pas en charge "If-Modified-Since" mais renvoie quand même un 200 OK?
Il existe quelques outils qui vérifient si votre site Web prend en charge "If-Modified-Since", donc je suppose que je demande comment ils fonctionnent.
Edit:
J'ai effectué quelques tests en utilisant Curl, l'envoi de ce qui suit:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',time()+60*60*60*60)));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
c'est-à-dire une date dans le futur google.com revient;
HTTP/1.0 304 Not Modified
Date: Fri, 05 Feb 2010 16:11:54 GMT
Server: gws
X-XSS-Protection: 0
X-Cache: MISS from .
Via: 1.0 .:80 (squid)
Connection: close
et si j'envoie;
curl_setopt($ch, CURLOPT_HTTPHEADER, array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',time()-60*60*60*60)));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
En d'autres termes, date google.com renvoie;
HTTP/1.0 200 OK
Date: Fri, 05 Feb 2010 16:09:12 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Server: gws
X-XSS-Protection: 0
X-Cache: MISS from .
Via: 1.0 .:80 (squid)
Connection: close
Si j'envoie alors les deux à bbc.co.uk (qui ne le supporte pas);
Le futur revient;
HTTP/1.1 200 OK
Date: Fri, 05 Feb 2010 16:12:51 GMT
Server: Apache
Set-Cookie: BBC-UID=84bb66bc648318e367bdca3ad1d48cf627005b54f090f211a2182074b4ed92c40ForbSoft%20Web%20Diagnostics%20%28URL%20Validator%29; expires=Tue, 04-Feb-14 16:12:51 GMT; path=/; domain=bbc.co.uk;
Accept-Ranges: bytes
Cache-Control: max-age=0
Expires: Fri, 05 Feb 2010 16:12:51 GMT
Pragma: no-cache
Content-Length: 111677
Content-Type: text/html
La date dans le passé est retournée;
HTTP/1.1 200 OK
Date: Fri, 05 Feb 2010 16:14:01 GMT
Server: Apache
Set-Cookie: BBC-UID=841b66ec44232cd91e81e88a014a3c5e50ed4e20c0e07174c4ff59675cd2fa210ForbSoft%20Web%20Diagnostics%20%28URL%20Validator%29; expires=Tue, 04-Feb-14 16:14:01 GMT; path=/; domain=bbc.co.uk;
Accept-Ranges: bytes
Cache-Control: max-age=0
Expires: Fri, 05 Feb 2010 16:14:01 GMT
Pragma: no-cache
Content-Length: 111672
Content-Type: text/html
Donc ma question est toujours là.
S'il vous plaît afficher les boucles que vous utilisez les commandes, je teste la ligne de commande et tout ce que je reçois est 200s, peu importe ce que j'envoie tête – adamJLev
Si le serveur ne supporte pas * If-Modified-Since * mais retourne toujours le code d'état 200, alors c'est comme si vous aviez envoyé la requête sans * If-Modified-Since * et le serveur répond avec le code d'état 200. Il n'y a pas de différence. 200 est 200, "La demande a réussi." – Gumbo
@Infinity - J'ai ajouté les commandes/options curl dans mon post original ci-dessus. –