From: Michael Wallner Date: Tue, 17 Feb 2015 14:08:50 +0000 (+0100) Subject: don't generate stat based etags for temp/mem streams X-Git-Tag: RELEASE_2_3_0_RC1~8 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d67af7f8dc8100a72ce2d5706c7d2f8d0d89796f;p=m6w6%2Fext-http don't generate stat based etags for temp/mem streams --- diff --git a/php_http_message_body.c b/php_http_message_body.c index 6129caf..ab1ec29 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -128,25 +128,29 @@ const char *php_http_message_body_boundary(php_http_message_body_t *body) char *php_http_message_body_etag(php_http_message_body_t *body) { - const php_stream_statbuf *ssb = php_http_message_body_stat(body); + php_http_etag_t *etag; + php_stream *s = php_http_message_body_stream(body); TSRMLS_FETCH_FROM_CTX(body->ts); /* real file or temp buffer ? */ - if (ssb && ssb->sb.st_mtime) { - char *etag; + if (s->ops != &php_stream_temp_ops && s->ops != &php_stream_memory_ops) { + php_stream_stat(php_http_message_body_stream(body), &body->ssb); - spprintf(&etag, 0, "%lx-%lx-%lx", ssb->sb.st_ino, ssb->sb.st_mtime, ssb->sb.st_size); - return etag; - } else { - php_http_etag_t *etag = php_http_etag_init(PHP_HTTP_G->env.etag_mode TSRMLS_CC); + if (body->ssb.sb.st_mtime) { + char *etag; - if (etag) { - php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_etag_update, etag, 0, 0); - return php_http_etag_finish(etag); - } else { - return NULL; + spprintf(&etag, 0, "%lx-%lx-%lx", body->ssb.sb.st_ino, body->ssb.sb.st_mtime, body->ssb.sb.st_size); + return etag; } } + + /* content based */ + if ((etag = php_http_etag_init(PHP_HTTP_G->env.etag_mode TSRMLS_CC))) { + php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_etag_update, etag, 0, 0); + return php_http_etag_finish(etag); + } + + return NULL; } void php_http_message_body_to_string(php_http_message_body_t *body, char **buf, size_t *len, off_t offset, size_t forlen) diff --git a/tests/envresponse018.phpt b/tests/envresponse018.phpt new file mode 100644 index 0000000..bed8526 --- /dev/null +++ b/tests/envresponse018.phpt @@ -0,0 +1,33 @@ +--TEST-- +env response don't generate stat based etag for temp stream +--SKIPIF-- + +--FILE-- +append("1234567890\n"); + +$r = new http\Env\Response; +$r->setBody($b); +$r->send(STDOUT); + +?> +===DONE=== +--EXPECTF-- +Test +HTTP/1.1 200 OK +Accept-Ranges: bytes +ETag: "%x" +Last-Modified: %s +Transfer-Encoding: chunked + +b +1234567890 + +0 + +===DONE===