From: Michael Wallner Date: Sat, 7 Oct 2006 12:46:22 +0000 (+0000) Subject: - attempt to fix bug #8872 (build fails --without-http-zlib-compression) X-Git-Tag: RELEASE_1_3_2~6 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=a694ce0dda4bc1ab0d1f1f3e365529b087c2a18f - attempt to fix bug #8872 (build fails --without-http-zlib-compression) - finally fix invalid detection wheter a deflated response should be started --- diff --git a/http_encoding_api.c b/http_encoding_api.c index 0de420a..2d20908 100644 --- a/http_encoding_api.c +++ b/http_encoding_api.c @@ -158,18 +158,22 @@ PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t enco /* }}} */ /* {{{ int http_encoding_response_start(size_t) */ -PHP_HTTP_API int _http_encoding_response_start(size_t content_length TSRMLS_DC) +PHP_HTTP_API int _http_encoding_response_start(size_t content_length, zend_bool ignore_http_ohandler TSRMLS_DC) { - int is_http = HTTP_G->send.deflate.encoding; - int is_zlib = php_ob_handler_used("ob_gzhandler" TSRMLS_CC) || php_ob_handler_used("zlib output compression" TSRMLS_CC); + int response = HTTP_G->send.deflate.response; + int ohandler = php_ob_handler_used("ob_gzhandler" TSRMLS_CC) || php_ob_handler_used("zlib output compression" TSRMLS_CC); - HTTP_G->send.deflate.encoding = 0; + if (!ohandler && !ignore_http_ohandler) { + ohandler = php_ob_handler_used("ob_deflatehandler" TSRMLS_CC) || php_ob_handler_used("http deflate" TSRMLS_CC); + } - if (is_http && !is_zlib) { + if (response && !ohandler) { #ifdef HTTP_HAVE_ZLIB HashTable *selected; zval zsupported; + HTTP_G->send.deflate.encoding = 0; + INIT_PZVAL(&zsupported); array_init(&zsupported); add_next_index_stringl(&zsupported, "gzip", lenof("gzip"), 1); @@ -202,14 +206,17 @@ PHP_HTTP_API int _http_encoding_response_start(size_t content_length TSRMLS_DC) zval_dtor(&zsupported); #else + HTTP_G->send.deflate.encoding = 0; php_start_ob_buffer_named("ob_gzhandler", 0, 0 TSRMLS_CC); #endif /* HTTP_HAVE_ZLIB */ - } else if (content_length && !is_zlib) { + } else if (content_length && !ohandler) { /* emit a content-length header */ char cl_header_str[128]; size_t cl_header_len; cl_header_len = snprintf(cl_header_str, lenof(cl_header_str), "Content-Length: %zu", content_length); http_send_header_string_ex(cl_header_str, cl_header_len, 1); + } else { + HTTP_G->send.deflate.encoding = 0; } return HTTP_G->send.deflate.encoding; @@ -651,6 +658,8 @@ PHP_HTTP_API void _http_encoding_inflate_stream_free(http_encoding_stream **s TS /* {{{ void http_ob_deflatehandler(char *, uint, char **, uint *, int) */ void _http_ob_deflatehandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) { + int encoding; + *handled_output = NULL; *handled_output_len = 0; @@ -662,9 +671,11 @@ void _http_ob_deflatehandler(char *output, uint output_len, char **handled_outpu return; } - HTTP_G->send.deflate.encoding = !0; + HTTP_G->send.deflate.response = 1; + encoding = http_encoding_response_start(0, 1); + HTTP_G->send.deflate.response = 0; - switch (http_encoding_response_start(0)) { + switch (encoding) { case HTTP_ENCODING_GZIP: flags = HTTP_DEFLATE_TYPE_GZIP; break; diff --git a/http_response_object.c b/http_response_object.c index d7be403..8b00412 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -1154,7 +1154,7 @@ PHP_METHOD(HttpResponse, send) } /* gzip */ - HTTP_G->send.deflate.encoding = zval_is_true(GET_STATIC_PROP(gzip)); + HTTP_G->send.deflate.response = zval_is_true(GET_STATIC_PROP(gzip)); /* send */ switch (Z_LVAL_P(GET_STATIC_PROP(mode))) { diff --git a/http_send_api.c b/http_send_api.c index 2be92b6..d1a2ebe 100644 --- a/http_send_api.c +++ b/http_send_api.c @@ -51,7 +51,7 @@ static inline void _http_send_response_start(void **buffer, size_t content_lengt { int encoding; - if ((encoding = http_encoding_response_start(content_length))) { + if ((encoding = http_encoding_response_start(content_length, 0))) { #ifdef HTTP_HAVE_ZLIB *buffer = http_encoding_deflate_stream_init(NULL, (encoding == HTTP_ENCODING_GZIP) ? @@ -65,7 +65,7 @@ static inline void _http_send_response_start(void **buffer, size_t content_lengt #define http_send_response_data_plain(b, d, dl) _http_send_response_data_plain((b), (d), (dl) TSRMLS_CC) static inline void _http_send_response_data_plain(void **buffer, const char *data, size_t data_len TSRMLS_DC) { - if (HTTP_G->send.deflate.encoding && *(http_encoding_stream **) buffer) { + if (HTTP_G->send.deflate.response && HTTP_G->send.deflate.encoding) { #ifdef HTTP_HAVE_ZLIB char *encoded; size_t encoded_len; @@ -137,7 +137,7 @@ static inline void _http_send_response_data_fetch(void **buffer, const void *dat #define http_send_response_finish(b) _http_send_response_finish((b) TSRMLS_CC) static inline void _http_send_response_finish(void **buffer TSRMLS_DC) { - if (HTTP_G->send.deflate.encoding && *(http_encoding_stream **) buffer) { + if (HTTP_G->send.deflate.response && HTTP_G->send.deflate.encoding) { #ifdef HTTP_HAVE_ZLIB char *encoded = NULL; size_t encoded_len = 0; diff --git a/package2.xml b/package2.xml index 83fece3..17b6404 100644 --- a/package2.xml +++ b/package2.xml @@ -28,9 +28,9 @@ support. Parallel requests are available for PHP 5 and greater. mike@php.net yes - 2006-10-02 + 2006-10-07 - 1.3.1 + 1.3.2 1.3.0 @@ -39,8 +39,8 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised diff --git a/php_http.h b/php_http.h index c93067e..a23ac69 100644 --- a/php_http.h +++ b/php_http.h @@ -15,7 +15,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define PHP_EXT_HTTP_VERSION "1.3.1" +#define PHP_EXT_HTTP_VERSION "1.3.2" #ifdef HAVE_CONFIG_H # include "config.h" @@ -102,6 +102,7 @@ ZEND_BEGIN_MODULE_GLOBALS(http) char *unquoted_etag; time_t last_modified; struct _http_globals_send_deflate { + zend_bool response; zend_bool start_auto; long start_flags; int encoding; diff --git a/php_http_encoding_api.h b/php_http_encoding_api.h index 8ebddba..4f0afd8 100644 --- a/php_http_encoding_api.h +++ b/php_http_encoding_api.h @@ -18,8 +18,8 @@ #define http_encoding_dechunk(e, el, d, dl) _http_encoding_dechunk((e), (el), (d), (dl) TSRMLS_CC) PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC); -#define http_encoding_response_start(cl) _http_encoding_response_start((cl) TSRMLS_CC) -PHP_HTTP_API int _http_encoding_response_start(size_t content_length TSRMLS_DC); +#define http_encoding_response_start(cl, i) _http_encoding_response_start((cl), (i) TSRMLS_CC) +PHP_HTTP_API int _http_encoding_response_start(size_t content_length, zend_bool ignore_http_ohandler TSRMLS_DC); #ifdef HTTP_HAVE_ZLIB