/* caching */
if (zval_is_true(GET_STATIC_PROP(cache))) {
zval *cctl, *cctl_p, *etag, *etag_p, *lmod, *lmod_p;
-
+
etag = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag), &etag_p);
lmod = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified), &lmod_p);
cctl = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl), &cctl_p);
-
- http_cache_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
- http_cache_last_modified(Z_LVAL_P(lmod), Z_LVAL_P(lmod) ? Z_LVAL_P(lmod) : HTTP_GET_REQUEST_TIME(), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
-
+
+ if (Z_LVAL_P(lmod) || Z_STRLEN_P(etag)) {
+ http_send_cache_control(Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
+ if (Z_STRLEN_P(etag)) {
+ http_send_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag));
+ }
+ if (Z_LVAL_P(lmod)) {
+ http_send_last_modified(Z_LVAL_P(lmod));
+ }
+ }
+
if (etag_p) zval_ptr_dtor(&etag_p);
if (lmod_p) zval_ptr_dtor(&lmod_p);
if (cctl_p) zval_ptr_dtor(&cctl_p);
-
- if (php_ob_handler_used("blackhole" TSRMLS_CC)) {
- RETURN_TRUE;
- }
}
/* content type */
case SEND_DATA:
{
zval *zdata_p, *zdata = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(data), &zdata_p);
- RETVAL_SUCCESS(http_send_data_ex(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata), 1));
+ RETVAL_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)));
if (zdata_p) zval_ptr_dtor(&zdata_p);
return;
}
zval *the_stream_p, *the_stream = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(stream), &the_stream_p);
the_stream->type = IS_RESOURCE;
php_stream_from_zval(the_real_stream, &the_stream);
- RETVAL_SUCCESS(http_send_stream_ex(the_real_stream, 0, 1));
+ RETVAL_SUCCESS(http_send_stream(the_real_stream));
if (the_stream_p) zval_ptr_dtor(&the_stream_p);
return;
}
default:
{
zval *file_p;
- RETVAL_SUCCESS(http_send_file_ex(Z_STRVAL_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file), &file_p)), 1));
+ RETVAL_SUCCESS(http_send_file(Z_STRVAL_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file), &file_p))));
if (file_p) zval_ptr_dtor(&file_p);
return;
}
{
STATUS status;
char *etag_header;
+ size_t etag_header_len;
if (!etag_len){
http_error_ex(HE_WARNING, HTTP_E_HEADER, "Attempt to send empty ETag (previous: %s)\n", HTTP_G->send.unquoted_etag);
return FAILURE;
}
+ etag_header_len = spprintf(&etag_header, 0, "ETag: \"%s\"", etag);
+ status = http_send_header_string_ex(etag_header, etag_header_len, 1);
+
/* remember */
STR_SET(HTTP_G->send.unquoted_etag, estrndup(etag, etag_len));
- etag_len = spprintf(&etag_header, 0, "ETag: \"%s\"", etag);
- status = http_send_header_string_ex(etag_header, etag_len, 1);
-
if (sent_header) {
*sent_header = etag_header;
} else {
void *s = NULL;
HashTable ranges;
http_range_status range_status;
- int cache_etag = http_interrupt_ob_etaghandler();
if (!data_ptr) {
return FAILURE;
case RANGE_NO:
{
zend_hash_destroy(&ranges);
-
+
/* send 304 Not Modified if etag matches - DON'T return on ETag generation failure */
- if (!no_cache && cache_etag) {
+ if (!no_cache && (http_interrupt_ob_etaghandler() || (HTTP_G->send.unquoted_etag != NULL))) {
char *etag = NULL;
- if ((etag = http_etag(data_ptr, data_size, data_mode))) {
+ if (HTTP_G->send.unquoted_etag) {
+ etag = estrdup(HTTP_G->send.unquoted_etag);
+ }
+
+ if (etag || (etag = http_etag(data_ptr, data_size, data_mode))) {
char *sent_header = NULL;
http_send_etag_ex(etag, strlen(etag), &sent_header);
return http_exit_ex(304, sent_header, NULL, 0);
} else {
STR_FREE(sent_header);
+ /* no caching for Last-Modified if ETags really don't match */
+ no_cache = http_got_server_var("HTTP_IF_NONE_MATCH");
}
efree(etag);
}
* Fixed Bug #7192: Build against libcurl >= 7.15.2 fails
* Fixed access of super globals
* Fixed sending userspace streams
+* Fixed too aggressive caching behavour of HttpResponse
]]></notes>
<contents>
<dir name="/">
?>
--EXPECTF--
X-Powered-By: PHP/%s
-ETag: "3858f62230ac3c915f300c664312c63f"
Cache-Control: public, must-revalidate, max-age=3600
Last-Modified: %s, %d %s 20%d %d:%d:%d GMT
Content-Type: %s
Accept-Ranges: bytes
+ETag: "3858f62230ac3c915f300c664312c63f"
Content-Length: 6
foobar
?>
--EXPECTF--
X-Powered-By: PHP/%s
-ETag: "%s"
Cache-Control: public, must-revalidate, max-age=3600
Last-Modified: %s, %d %s 20%d %d:%d:%d GMT
Content-Type: %s
Accept-Ranges: bytes
+ETag: "%s"
Content-Encoding: gzip
Vary: Accept-Encoding
include 'skip.inc';
checkcgi();
checkmin(5.1);
-skpif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib support");
+skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib support");
?>
---ENV--
-HTTP_ACCEPT_ENCODING=gzip
-HTTP_IF_NONE_MATCH="80b285463881575891e86ba7bfecb4d0"
--FILE--
<?php
+$_SERVER["HTTP_IF_NONE_MATCH"] = '"900150983cd24fb0d6963f7d28e17f72"';
+$_SERVER["HTTP_ACCEPT_ENCODING"] = "gzip";
HttpResponse::setGzip(true);
HttpResponse::setCache(true);
HttpResponse::setCacheControl('public', 3600);
-HttpResponse::setData(file_get_contents(__FILE__));
+HttpResponse::setData("abc");
HttpResponse::send();
?>
--EXPECTF--
Status: 304
X-Powered-By: PHP/%s
Cache-Control: public, must-revalidate, max-age=3600
-ETag: "80b285463881575891e86ba7bfecb4d0"
-Content-type: %s
+Last-Modified: %s
+Content-Type: %s
+Accept-Ranges: bytes
+ETag: "900150983cd24fb0d6963f7d28e17f72"