- add flush() to HttpDeflateStream and HttpInflateStream
[m6w6/ext-http] / http_encoding_api.c
index 8c121bcd56bc69a2c6cf575d4e7d864bb381b98d..a31b5b79772cc0533c2af23274674cdb158db89d 100644 (file)
@@ -24,8 +24,6 @@
 #include "php_http_send_api.h"
 #include "php_http_headers_api.h"
 
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
 #ifdef HTTP_HAVE_ZLIB
 PHP_MINIT_FUNCTION(http_encoding)
 {
@@ -42,6 +40,32 @@ PHP_MINIT_FUNCTION(http_encoding)
        HTTP_LONG_CONSTANT("HTTP_DEFLATE_STRATEGY_FIXED", HTTP_DEFLATE_STRATEGY_FIXED);
        return SUCCESS;
 }
+
+PHP_RINIT_FUNCTION(http_encoding)
+{
+       getGlobals(G);
+       
+       if (G->send.inflate.start_auto) {
+               php_ob_set_internal_handler(_http_ob_inflatehandler, 0x1000, "http inflate", 0 TSRMLS_CC);
+       }
+       if (G->send.deflate.start_auto) {
+               php_ob_set_internal_handler(_http_ob_deflatehandler, 0x8000, "http deflate", 0 TSRMLS_CC);
+       }
+       return SUCCESS;
+}
+
+PHP_RSHUTDOWN_FUNCTION(http_encoding)
+{
+       getGlobals(G);
+       
+       if (G->send.deflate.stream) {
+               http_encoding_deflate_stream_free((http_encoding_stream **) &G->send.deflate.stream);
+       }
+       if (G->send.inflate.stream) {
+               http_encoding_inflate_stream_free((http_encoding_stream **) &G->send.inflate.stream);
+       }
+       return SUCCESS;
+}
 #endif
 
 static inline int eol_match(char **line, int *eol_len)
@@ -193,7 +217,7 @@ PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t enco
 #define HTTP_WINDOW_BITS_ANY   0x0000002f
 #define HTTP_WINDOW_BITS_RAW   -0x000000f
 
-STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status, level, wbits, strategy;
        z_stream Z;
@@ -209,7 +233,7 @@ STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char
        status = deflateInit2(&Z, level, Z_DEFLATED, wbits, MAX_MEM_LEVEL, strategy);
        if (Z_OK == status) {
                *encoded_len = HTTP_ENCODING_BUFLEN(data_len);
-               *encoded = emalloc(*encoded_len);
+               *encoded = emalloc_rel(*encoded_len);
                
                Z.next_in = (Bytef *) data;
                Z.next_out = (Bytef *) *encoded;
@@ -221,7 +245,7 @@ STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char
                
                if (Z_STREAM_END == status) {
                        /* size buffer down to actual length */
-                       *encoded = erealloc(*encoded, Z.total_out + 1);
+                       *encoded = erealloc_rel(*encoded, Z.total_out + 1);
                        (*encoded)[*encoded_len = Z.total_out] = '\0';
                        return SUCCESS;
                } else {
@@ -234,7 +258,7 @@ STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char
        return FAILURE;
 }
 
-STATUS _http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status, max = 0, wbits = HTTP_WINDOW_BITS_ANY;
        z_stream Z;
@@ -258,7 +282,7 @@ retry_inflate:
 
                        do {
                                Z.avail_out = (buffer.free -= Z.total_out - buffer.used);
-                               Z.next_out = buffer.data + (buffer.used = Z.total_out);
+                               Z.next_out = (Bytef *) buffer.data + (buffer.used = Z.total_out);
                                status = inflate(&Z, Z_NO_FLUSH);
                        } while (Z_OK == status);
                } while (Z_BUF_ERROR == status && ++max < HTTP_ENCODING_MAXTRY);
@@ -274,7 +298,7 @@ retry_inflate:
                
                if (Z_STREAM_END == status) {
                        *decoded_len = Z.total_out;
-                       *decoded = erealloc(buffer.data, *decoded_len + 1);
+                       *decoded = erealloc_rel(buffer.data, *decoded_len + 1);
                        (*decoded)[*decoded_len] = '\0';
                        return SUCCESS;
                } else {
@@ -287,12 +311,12 @@ retry_inflate:
 }
 
 
-http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC)
+PHP_HTTP_API http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status, level, wbits, strategy, free_stream;
        
        if ((free_stream = !s)) {
-               s = pemalloc(sizeof(http_encoding_stream), (flags & HTTP_ENCODING_STREAM_PERSISTENT));
+               s = pemalloc_rel(sizeof(http_encoding_stream), (flags & HTTP_ENCODING_STREAM_PERSISTENT));
        }
        memset(s, 0, sizeof(http_encoding_stream));
        s->flags = flags;
@@ -318,12 +342,12 @@ http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s
        return NULL;
 }
 
-http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC)
+PHP_HTTP_API http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status, wbits, free_stream;
        
        if ((free_stream = !s)) {
-               s = emalloc(sizeof(http_encoding_stream));
+               s = pemalloc_rel(sizeof(http_encoding_stream), (flags & HTTP_ENCODING_STREAM_PERSISTENT));
        }
        memset(s, 0, sizeof(http_encoding_stream));
        s->flags = flags;
@@ -347,30 +371,32 @@ http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s
        return NULL;
 }
 
-STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status;
        
        /* append input to our buffer */
        phpstr_append(PHPSTR(s->stream.opaque), data, data_len);
        
-       s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+       s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
        s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
        
        /* deflate */
-       s->stream.avail_out = *encoded_len = HTTP_ENCODING_BUFLEN(data_len);
-       s->stream.next_out = *encoded = emalloc(*encoded_len);
+       *encoded_len = HTTP_ENCODING_BUFLEN(data_len);
+       *encoded = emalloc_rel(*encoded_len);
+       s->stream.avail_out = *encoded_len;
+       s->stream.next_out = (Bytef *) *encoded;
        
        switch (status = deflate(&s->stream, Z_NO_FLUSH))
        {
                case Z_OK:
                case Z_STREAM_END:
                        /* cut processed chunk off the buffer */
-                       phpstr_cut(PHPSTR(s->stream.opaque), 0, data_len - s->stream.avail_in);
+                       phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
                        
                        /* size buffer down to actual size */
                        *encoded_len -= s->stream.avail_out;
-                       *encoded = erealloc(*encoded, *encoded_len + 1);
+                       *encoded = erealloc_rel(*encoded, *encoded_len + 1);
                        (*encoded)[*encoded_len] = '\0';
                        return SUCCESS;
                break;
@@ -382,7 +408,7 @@ STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char
        return FAILURE;
 }
 
-STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status, max = 0;
        
@@ -396,13 +422,13 @@ STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char
        /* inflate */
        do {
                *decoded_len <<= 1;
-               *decoded = erealloc(*decoded, *decoded_len);
+               *decoded = erealloc_rel(*decoded, *decoded_len);
                
 retry_raw_inflate:
-               s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+               s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
                s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
        
-               s->stream.next_out = *decoded;
+               s->stream.next_out = (Bytef *) *decoded;
                s->stream.avail_out = *decoded_len;
                
                switch (status = inflate(&s->stream, Z_NO_FLUSH))
@@ -410,11 +436,11 @@ retry_raw_inflate:
                        case Z_OK:
                        case Z_STREAM_END:
                                /* cut off */
-                               phpstr_cut(PHPSTR(s->stream.opaque), 0, data_len - s->stream.avail_in);
+                               phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
                                
                                /* size down */
                                *decoded_len -= s->stream.avail_out;
-                               *decoded = erealloc(*decoded, *decoded_len + 1);
+                               *decoded = erealloc_rel(*decoded, *decoded_len + 1);
                                (*decoded)[*decoded_len] = '\0';
                                return SUCCESS;
                        break;
@@ -433,20 +459,59 @@ retry_raw_inflate:
        
        STR_SET(*decoded, NULL);
        *decoded_len = 0;
-       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not update inflate stream: %s", zError(status));
+       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to update inflate stream: %s", zError(status));
        return FAILURE;
 }
 
-STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(http_encoding_stream *s, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status;
        
+       *encoded_len = 0x800;
+       *encoded = emalloc_rel(*encoded_len);
+       
+       s->stream.avail_in = 0;
+       s->stream.next_in = NULL;
+       s->stream.avail_out = *encoded_len;
+       s->stream.next_out = (Bytef *) *encoded;
+       
+       switch (status = deflate(&s->stream, Z_SYNC_FLUSH))
+       {
+               case Z_OK:
+               case Z_STREAM_END:
+                       *encoded_len = 0x800 - s->stream.avail_out;
+                       *encoded = erealloc_rel(*encoded, *encoded_len + 1);
+                       (*encoded)[*encoded_len] = '\0';
+                       return SUCCESS;
+               break;
+       }
+       
+       STR_SET(*encoded, NULL);
+       *encoded_len = 0;
+       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to flush deflate stream: %s", zError(status));
+       return FAILURE;
+}
+
+PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
+{
+       /* noop */
+       *decoded = estrndup("", *decoded_len = 0);
+       return SUCCESS;
+}
+
+PHP_HTTP_API STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
+{
+       int status;
+       
+       *encoded_len = 0x800;
+       *encoded = emalloc_rel(*encoded_len);
+       
        /* deflate remaining input */
-       s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+       s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
        s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
        
-       s->stream.avail_out = *encoded_len = 0x800;
-       s->stream.next_out = *encoded = emalloc(*encoded_len);
+       s->stream.avail_out = *encoded_len;
+       s->stream.next_out = (Bytef *) *encoded;
        
        do {
                status = deflate(&s->stream, Z_FINISH);
@@ -458,7 +523,7 @@ STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **enco
                
                /* size down */
                *encoded_len -= s->stream.avail_out;
-               *encoded = erealloc(*encoded, *encoded_len + 1);
+               *encoded = erealloc_rel(*encoded, *encoded_len + 1);
                (*encoded)[*encoded_len] = '\0';
                return SUCCESS;
        }
@@ -469,16 +534,19 @@ STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **enco
        return FAILURE;
 }
 
-STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
        int status;
        
+       *decoded_len = s->stream.avail_in << 2;
+       *decoded = emalloc_rel(*decoded_len);
+       
        /* inflate remaining input */
-       s->stream.next_in = PHPSTR_VAL(s->stream.opaque);
+       s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
        s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
        
-       s->stream.avail_out = *decoded_len = s->stream.avail_in << 2;
-       s->stream.next_out = *decoded = emalloc(*decoded_len);
+       s->stream.avail_out = *decoded_len;
+       s->stream.next_out = (Bytef *) *decoded;
        
        if (Z_STREAM_END == (status = inflate(&s->stream, Z_FINISH))) {
                /* cut processed input off */
@@ -486,7 +554,7 @@ STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **deco
                
                /* size down */
                *decoded_len -= s->stream.avail_out;
-               *decoded = erealloc(*decoded, *decoded_len + 1);
+               *decoded = erealloc_rel(*decoded, *decoded_len + 1);
                (*decoded)[*decoded_len] = '\0';
                return SUCCESS;
        }
@@ -497,7 +565,7 @@ STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **deco
        return FAILURE;
 }
 
-void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
 {
        if (s) {
                if (s->stream.opaque) {
@@ -507,7 +575,7 @@ void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
        }
 }
 
-void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
 {
        if (s) {
                if (s->stream.opaque) {
@@ -517,7 +585,7 @@ void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
        }
 }
 
-void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC)
 {
        if (s) {
                http_encoding_deflate_stream_dtor(*s);
@@ -528,7 +596,7 @@ void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC)
        }
 }
 
-void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC)
 {
        if (s) {
                http_encoding_inflate_stream_dtor(*s);
@@ -539,6 +607,100 @@ void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC)
        }
 }
 
+void _http_ob_deflatehandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
+{
+       getGlobals(G);
+       
+       *handled_output = NULL;
+       *handled_output_len = 0;
+       
+       if (mode & PHP_OUTPUT_HANDLER_START) {
+               int flags;
+               
+               if (G->send.deflate.stream) {
+                       zend_error(E_ERROR, "ob_deflatehandler() can only be used once");
+                       return;
+               }
+               
+               G->send.deflate.encoding = !0;
+               
+               switch (http_encoding_response_start(0))
+               {
+                       case HTTP_ENCODING_GZIP:
+                               flags = HTTP_DEFLATE_TYPE_GZIP;
+                       break;
+                       
+                       case HTTP_ENCODING_DEFLATE:
+                               flags = HTTP_DEFLATE_TYPE_ZLIB;
+                       break;
+                       
+                       default:
+                               goto deflate_passthru_plain;
+                       break;
+               }
+               
+               flags |= (G->send.deflate.start_flags &~ 0xf0);
+               G->send.deflate.stream = http_encoding_deflate_stream_init(NULL, flags);
+       }
+       
+       if (G->send.deflate.stream) {
+               http_encoding_deflate_stream_update((http_encoding_stream *) G->send.deflate.stream, output, output_len, handled_output, handled_output_len);
+               
+               if (mode & PHP_OUTPUT_HANDLER_END) {
+                       char *remaining = NULL;
+                       size_t remaining_len = 0;
+                       
+                       http_encoding_deflate_stream_finish((http_encoding_stream *) G->send.deflate.stream, &remaining, &remaining_len);
+                       http_encoding_deflate_stream_free((http_encoding_stream **) &G->send.deflate.stream);
+                       if (remaining) {
+                               *handled_output = erealloc(*handled_output, *handled_output_len + remaining_len + 1);
+                               memcpy(*handled_output + *handled_output_len, remaining, remaining_len);
+                               (*handled_output)[*handled_output_len += remaining_len] = '\0';
+                               efree(remaining);
+                       }
+               }
+       } else {
+deflate_passthru_plain:
+               *handled_output = estrndup(output, *handled_output_len = output_len);
+       }
+}
+
+void _http_ob_inflatehandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
+{
+       getGlobals(G);
+       
+       *handled_output = NULL;
+       *handled_output_len = 0;
+       
+       if (mode & PHP_OUTPUT_HANDLER_START) {
+               if (G->send.inflate.stream) {
+                       zend_error(E_ERROR, "ob_inflatehandler() can only be used once");
+                       return;
+               }
+               G->send.inflate.stream = http_encoding_inflate_stream_init(NULL, (HTTP_G(send).inflate.start_flags &~ 0xf0));
+       }
+       
+       if (G->send.inflate.stream) {
+               http_encoding_inflate_stream_update((http_encoding_stream *) G->send.inflate.stream, output, output_len, handled_output, handled_output_len);
+               
+               if (mode & PHP_OUTPUT_HANDLER_END) {
+                       char *remaining = NULL;
+                       size_t remaining_len = 0;
+                       
+                       http_encoding_inflate_stream_finish((http_encoding_stream *) G->send.inflate.stream, &remaining, &remaining_len);
+                       http_encoding_inflate_stream_free((http_encoding_stream **) &G->send.inflate.stream);
+                       if (remaining) {
+                               *handled_output = erealloc(*handled_output, *handled_output_len + remaining_len + 1);
+                               memcpy(*handled_output + *handled_output_len, remaining, remaining_len);
+                               (*handled_output)[*handled_output_len += remaining_len] = '\0';
+                               efree(remaining);
+                       }
+               }
+       } else {
+               *handled_output = estrndup(output, *handled_output_len = output_len);
+       }
+}
+
 static const char http_encoding_gzip_header[] = {
        (const char) 0x1f,                      // fixed value
        (const char) 0x8b,                      // fixed value
@@ -667,13 +829,13 @@ PHP_HTTP_API STATUS _http_encoding_gzdecode_verify(const char *data, size_t data
 
 #endif /* HTTP_HAVE_ZLIB */
 
-PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRMLS_DC)
+PHP_HTTP_API int _http_encoding_response_start(size_t content_length TSRMLS_DC)
 {
        if (    php_ob_handler_used("ob_gzhandler" TSRMLS_CC) ||
                        php_ob_handler_used("zlib output compression" TSRMLS_CC)) {
-               HTTP_G(send).gzip_encoding = 0;
+               HTTP_G(send).deflate.encoding = 0;
        } else {
-               if (!HTTP_G(send).gzip_encoding) {
+               if (!HTTP_G(send).deflate.encoding) {
                        /* emit a content-length header */
                        if (content_length) {
                                char cl_header_str[128];
@@ -683,7 +845,7 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML
                        }
                } else {
 #ifndef HTTP_HAVE_ZLIB
-                       HTTP_G(send).gzip_encoding = 0;
+                       HTTP_G(send).deflate.encoding = 0;
                        php_start_ob_buffer_named("ob_gzhandler", 0, 0 TSRMLS_CC);
 #else
                        HashTable *selected;
@@ -695,7 +857,7 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML
                        add_next_index_stringl(&zsupported, "x-gzip", lenof("x-gzip"), 1);
                        add_next_index_stringl(&zsupported, "deflate", lenof("deflate"), 1);
                        
-                       HTTP_G(send).gzip_encoding = 0;
+                       HTTP_G(send).deflate.encoding = 0;
                        
                        if ((selected = http_negotiate_encoding(&zsupported))) {
                                STATUS hs = FAILURE;
@@ -705,11 +867,11 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML
                                if (HASH_KEY_IS_STRING == zend_hash_get_current_key(selected, &encoding, &idx, 0) && encoding) {
                                        if (!strcmp(encoding, "gzip") || !strcmp(encoding, "x-gzip")) {
                                                if (SUCCESS == (hs = http_send_header_string("Content-Encoding: gzip"))) {
-                                                       HTTP_G(send).gzip_encoding = HTTP_ENCODING_GZIP;
+                                                       HTTP_G(send).deflate.encoding = HTTP_ENCODING_GZIP;
                                                }
                                        } else if (!strcmp(encoding, "deflate")) {
                                                if (SUCCESS == (hs = http_send_header_string("Content-Encoding: deflate"))) {
-                                                       HTTP_G(send).gzip_encoding = HTTP_ENCODING_DEFLATE;
+                                                       HTTP_G(send).deflate.encoding = HTTP_ENCODING_DEFLATE;
                                                }
                                        }
                                        if (SUCCESS == hs) {
@@ -722,7 +884,7 @@ PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML
                        }
                        
                        zval_dtor(&zsupported);
-                       return HTTP_G(send).gzip_encoding;
+                       return HTTP_G(send).deflate.encoding;
 #endif
                }
        }