+ if (external_gzip_handlers) {
+#ifdef HTTP_HAVE_ZLIB
+ if (HTTP_G(send).gzip_encoding) {
+ HTTP_G(send).gzip_encoding = 0;
+ }
+ } else if (HTTP_G(send).gzip_encoding) {
+ HashTable *selected;
+ zval zsupported;
+
+ INIT_PZVAL(&zsupported);
+ array_init(&zsupported);
+ add_next_index_stringl(&zsupported, "gzip", lenof("gzip"), 1);
+ add_next_index_stringl(&zsupported, "deflate", lenof("deflate"), 1);
+ add_next_index_stringl(&zsupported, "compress", lenof("compress"), 1);
+
+ if (selected = http_negotiate_encoding(&zsupported)) {
+ char *encoding = NULL;
+ ulong idx;
+
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key(selected, &encoding, &idx, 0) && encoding) {
+ STATUS hs = FAILURE;
+
+ if (!strcmp(encoding, "gzip")) {
+ if (SUCCESS == (hs = http_send_header_string("Content-Encoding: gzip"))) {
+ HTTP_G(send).gzip_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;
+ }
+ } else if (!strcmp(encoding, "compress")) {
+ if (SUCCESS == (hs = http_send_header_string("Content-Encoding: compress"))) {
+ HTTP_G(send).gzip_encoding = HTTP_ENCODING_COMPRESS;
+ }
+ }
+ if (SUCCESS == hs) {
+ http_send_header_string("Vary: Accept-Encoding");
+ } else {
+ HTTP_G(send).gzip_encoding = 0;
+ }
+ }
+
+ zend_hash_destroy(selected);
+ FREE_HASHTABLE(selected);
+ }
+
+ zval_dtor(&zsupported);
+#endif
+ } else {
+ /* emit a content-length header */