Стоит ли отдавать контент?

12 3
Y
На сайте с 20.05.2004
Offline
103
yas
2028

Я с помощью If-Modified-Since проверяю был ли изменен контент, и если не бы то отдаю заголовок:

header ('HTTP/1.0 304 Not Modified');

Но вопрос нужно ли выводить дальше контент, или обязательное условие это отсутствие контента?

deadcat
На сайте с 04.04.2005
Offline
27
#1

http://seolab.ru/add/rfc2068/82.html

Там написано: Отклик 304 не должен включать в себя тело сообщения и, по этой причине всегда завершается пустой строкой после полей заголовка.

Но, 304 надо возвращать только тогда, когда клиент передал заголовок If-Modified-Since.

valentin shergin research laboratory (http://shergin.com), erratum machine – самоорганизация документов, cms, cmf (http://erratum.ru)
Y
На сайте с 20.05.2004
Offline
103
yas
#2

То есть нужно проверять и на If-Modified-Since и на user agent ботов да?

Artisan
На сайте с 04.03.2005
Offline
375
#3

Идентификаторы ботов здесь ни при чем.

Согласно HTTP/1.1 стандарту

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

запрос GET без условий = отдать весь документ,

запрос HEAD без условий = отдать только заголовки,

и есть дополнительные условия.

14.25 If-Modified-Since

The If-Modified-Since request-header field is used with a method to make it conditional: if the requested variant has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message-body.

If-Modified-Since = "If-Modified-Since" ":" HTTP-date

An example of the field is:

If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT

A GET method with an If-Modified-Since header and no Range header requests that the identified entity be transferred only if it has been modified since the date given by the If-Modified-Since header. The algorithm for determining this includes the following cases:

a) If the request would normally result in anything other than a
200 (OK) status, or if the passed If-Modified-Since date is
invalid, the response is exactly the same as for a normal GET.
A date which is later than the server's current time is
invalid.

b) If the variant has been modified since the If-Modified-Since
date, the response is exactly the same as for a normal GET.

c) If the variant has not been modified since a valid If-
Modified-Since date, the server SHOULD return a 304 (Not
Modified) response.

The purpose of this feature is to allow efficient updates of cached information with a minimum amount of transaction overhead.

Note: The Range request-header field modifies the meaning of If-
Modified-Since; see section 14.35 for full details.

Note: If-Modified-Since times are interpreted by the server, whose
clock might not be synchronized with the client.

Note: When handling an If-Modified-Since header field, some
servers will use an exact date comparison function, rather than a
less-than function, for deciding whether to send a 304 (Not
Modified) response. To get best results when sending an If-
Modified-Since header field for cache validation, clients are
advised to use the exact date string received in a previous Last-
Modified header field whenever possible.

Note: If a client uses an arbitrary date in the If-Modified-Since
header instead of a date taken from the Last-Modified header for
the same request, the client should be aware of the fact that this
date is interpreted in the server's understanding of time. The
client should consider unsynchronized clocks and rounding problems
due to the different encodings of time between the client and
server. This includes the possibility of race conditions if the
document has changed between the time it was first requested and
the If-Modified-Since date of a subsequent request, and the

possibility of clock-skew-related problems if the If-Modified-
Since date is derived from the client's clock without correction
to the server's clock. Corrections for different time bases
between client and server are at best approximate due to network
latency.

The result of a request having both an If-Modified-Since header field and either an If-Match or an If-Unmodified-Since header fields is undefined by this specification.
www.leak.info / ДАРОМ линки конкурентов и забытых доменов
Y
На сайте с 20.05.2004
Offline
103
yas
#4

Artisan, тогда как проверить на то что послан head запрос?

Artisan
На сайте с 04.03.2005
Offline
375
#5

Если используем CGI (а PHP делает похоже) то переменная окружения REQUEST_METHOD (которая у PHP в стандартном массиве) а если нет то можно самому разбирать запрос или использовать другие способы которые зависят от HTTP сервера и способа выполнения программы пользователя.

Y
На сайте с 20.05.2004
Offline
103
yas
#6

Понял, да есть уже протестил, то есть я проверяю если шлеться HEAD то я проверяю если есть изменения то шлю не изменен и ничего не вывожу да?

HEAD браузеры не могу слать да, не получиться ли так что я кому нить пустой экра выдам, если проверю на вид запроса?

Artisan
На сайте с 04.03.2005
Offline
375
#7

HEAD может запрашиваться броузером если документ уже есть в кэше но в любом случае согласно стандарту при таком запросе надо выдавать только заголовки.

Y
На сайте с 20.05.2004
Offline
103
yas
#8

Artisan, то есть можно напоросться) Жалко, а если отдать такоей header и контент, то бот индекснет да?

Artisan
На сайте с 04.03.2005
Offline
375
#9
Как писал yas
Artisan, то есть можно напоросться) Жалко, а если отдать такоей header и контент, то бот индекснет да?

Если у Вас сам броузер запрашивает только HEAD то зачем совать ему еще и сам документ? Делайте то и только то что написано в стандарте и будет Вам счастье.

Y
На сайте с 20.05.2004
Offline
103
yas
#10

Еще раз уточню:

Если head + If-Modified-Since то проверяю и если не изменен, то отдаю что не измене и ничего не выдаю да?

То вслучае, если кеш то пошлеться head и контент возьметься из кеша браузера

В другом случае если head то это бот!

Так?

12 3

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий