; composite log file (i.e. log all messages to this file)
;http.composite_log =
+
+; automatically deflate content if requested/supported by client
+;http.ob_deflate_auto = 1
+;http.ob_deflate_flags = HTTP_DEFLATE_LEVEL_DEF
+
+; automatically inflate compressed content
+;http.ob_inflate_auto = 0
+;http.ob_inflate_flags =
#ifdef HTTP_HAVE_ZLIB
PHP_FE(http_deflate, NULL)
PHP_FE(http_inflate, NULL)
+ PHP_FE(ob_deflatehandler, NULL)
+ PHP_FE(ob_inflatehandler, NULL)
#endif
PHP_FE(http_support, NULL)
memset(G, 0, sizeof(zend_http_globals));
}
-static inline void http_globals_init(zend_http_globals *G)
+#define http_globals_init(g) _http_globals_init((g) TSRMLS_CC)
+static inline void _http_globals_init(zend_http_globals *G TSRMLS_DC)
{
G->send.buffer_size = HTTP_SENDBUF_SIZE;
zend_hash_init(&G->request.methods.custom, 0, NULL, ZVAL_PTR_DTOR, 0);
}
-static inline void http_globals_free(zend_http_globals *G)
+#define http_globals_free(g) _http_globals_free((g) TSRMLS_CC)
+static inline void _http_globals_free(zend_http_globals *G TSRMLS_DC)
{
STR_SET(G->send.content_type, NULL);
STR_SET(G->send.unquoted_etag, NULL);
HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL, OnUpdateBool, only_exceptions)
#endif
HTTP_PHP_INI_ENTRY("http.force_exit", "1", PHP_INI_ALL, OnUpdateBool, force_exit)
+#ifdef HTTP_HAVE_ZLIB
+ HTTP_PHP_INI_ENTRY("http.ob_inflate_auto", "0", PHP_INI_PERDIR, OnUpdateBool, send.inflate.start_auto)
+ HTTP_PHP_INI_ENTRY("http.ob_inflate_flags", "0", PHP_INI_ALL, OnUpdateLong, send.inflate.start_flags)
+ HTTP_PHP_INI_ENTRY("http.ob_deflate_auto", "0", PHP_INI_PERDIR, OnUpdateBool, send.deflate.start_auto)
+ HTTP_PHP_INI_ENTRY("http.ob_deflate_flags", "0", PHP_INI_ALL, OnUpdateLong, send.deflate.start_flags)
+#endif
PHP_INI_END()
/* }}} */
}
http_globals_init(HTTP_GLOBALS);
+
+#ifdef HTTP_HAVE_ZLIB
+ if (SUCCESS != PHP_RINIT_CALL(http_encoding)) {
+ return FAILURE;
+ }
+#endif
+
return SUCCESS;
}
/* }}} */
{
STATUS status = SUCCESS;
+ if (
+#ifdef HTTP_HAVE_ZLIB
+ (SUCCESS != PHP_RSHUTDOWN_CALL(http_encoding)) ||
+#endif
#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
- status = PHP_RSHUTDOWN_CALL(http_request_method);
+ (SUCCESS != PHP_RSHUTDOWN_CALL(http_request_method)) ||
#endif
+ 0) {
+ status = FAILURE;
+ }
http_globals_free(HTTP_GLOBALS);
return status;
# include "php_http_exception_object.h"
#endif
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
PHP_MINIT_FUNCTION(http_support)
{
HTTP_LONG_CONSTANT("HTTP_SUPPORT", HTTP_SUPPORT);
#include "php_http_date_api.h"
#include "php_http_send_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
/* {{{ char *http_etag(void *, size_t, http_send_mode) */
PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC)
{
#include "php_http_api.h"
#include "php_http_date_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
static inline int check_day(const char *day, size_t len);
static inline int check_month(const char *month);
static inline int check_tzone(const char *tzone);
#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)
{
HTTP_LONG_CONSTANT("HTTP_DEFLATE_STRATEGY_FIXED", HTTP_DEFLATE_STRATEGY_FIXED);
return SUCCESS;
}
+
+PHP_RINIT_FUNCTION(http_encoding)
+{
+ if (HTTP_G(send).inflate.start_auto) {
+ php_ob_set_internal_handler(_http_ob_inflatehandler, 0x1000, "http inflate", 0 TSRMLS_CC);
+ }
+ if (HTTP_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)
+{
+ 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)
#define HTTP_WINDOW_BITS_ANY 0x0000002f
#define HTTP_WINDOW_BITS_RAW -0x000000f
-PHP_HTTP_API 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;
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;
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 {
return FAILURE;
}
-PHP_HTTP_API 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;
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 {
}
-PHP_HTTP_API 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;
return NULL;
}
-PHP_HTTP_API 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;
return NULL;
}
-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 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;
/* deflate */
*encoded_len = HTTP_ENCODING_BUFLEN(data_len);
- *encoded = emalloc(*encoded_len);
+ *encoded = emalloc_rel(*encoded_len);
s->stream.avail_out = *encoded_len;
s->stream.next_out = (Bytef *) *encoded;
/* 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;
return FAILURE;
}
-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 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;
/* inflate */
do {
*decoded_len <<= 1;
- *decoded = erealloc(*decoded, *decoded_len);
+ *decoded = erealloc_rel(*decoded, *decoded_len);
retry_raw_inflate:
s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
/* 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;
return FAILURE;
}
-PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(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(*encoded_len);
+ *encoded = emalloc_rel(*encoded_len);
s->stream.avail_in = 0;
s->stream.next_in = NULL;
case Z_OK:
case Z_STREAM_END:
*encoded_len = 0x800 - s->stream.avail_out;
- *encoded = erealloc(*encoded, *encoded_len + 1);
+ *encoded = erealloc_rel(*encoded, *encoded_len + 1);
(*encoded)[*encoded_len] = '\0';
return SUCCESS;
break;
return FAILURE;
}
-PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC)
+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)
{
int status;
*decoded_len = 0x800;
- *decoded = emalloc(*decoded_len);
+ *decoded = emalloc_rel(*decoded_len);
s->stream.avail_in = 0;
s->stream.next_in = NULL;
case Z_OK:
case Z_STREAM_END:
*decoded_len = 0x800 - s->stream.avail_out;
- *decoded = erealloc(*decoded, *decoded_len + 1);
+ *decoded = erealloc_rel(*decoded, *decoded_len + 1);
(*decoded)[*decoded_len] = '\0';
return SUCCESS;
break;
return FAILURE;
}
-PHP_HTTP_API 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_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(*encoded_len);
+ *encoded = emalloc_rel(*encoded_len);
/* deflate remaining input */
s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
/* 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;
}
return FAILURE;
}
-PHP_HTTP_API 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(*decoded_len);
+ *decoded = emalloc_rel(*decoded_len);
/* inflate remaining input */
s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
/* 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;
}
}
}
+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 &~ 0xf);
+ 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 &~ 0xf));
+ }
+
+ 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
#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];
}
} 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;
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;
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) {
}
zval_dtor(&zsupported);
- return HTTP_G(send).gzip_encoding;
+ return HTTP_G(send).deflate.encoding;
#endif
}
}
#include "php_http_send_api.h"
#include "php_http_url_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http)
-
/* {{{ proto string http_date([int timestamp])
*
* Compose a valid HTTP date regarding RFC 822/1123
RETVAL_NULL();
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &flags)) {
- {
- char *encoded;
- size_t encoded_len;
-
- if (SUCCESS == http_encoding_deflate(flags, data, data_len, &encoded, &encoded_len)) {
- RETURN_STRINGL(encoded, (int) encoded_len, 0);
- }
+ char *encoded;
+ size_t encoded_len;
+
+ if (SUCCESS == http_encoding_deflate(flags, data, data_len, &encoded, &encoded_len)) {
+ RETURN_STRINGL(encoded, (int) encoded_len, 0);
}
}
}
}
/* }}} */
+/* {{{ proto string ob_deflatehandler(string data, int mode)
+ *
+ * For use with ob_start(). The deflate output buffer handler can only be used once.
+ * It conflicts with ob_gzhanlder and zlib.output_compression as well and should
+ * not be used after ext/mbstrings mb_output_handler and ext/sessions URL-Rewriter (AKA
+ * session.use_trans_sid).
+ */
+PHP_FUNCTION(ob_deflatehandler)
+{
+ char *data;
+ int data_len;
+ long mode;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
+ RETURN_FALSE;
+ }
+
+ http_ob_deflatehandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
+ Z_TYPE_P(return_value) = Z_STRVAL_P(return_value) ? IS_STRING : IS_NULL;
+}
+/* }}} */
+
+/* {{{ proto string ob_inflatehandler(string data, int mode)
+ *
+ * For use with ob_start(). Same restrictions as with ob_deflatehandler apply.
+ */
+PHP_FUNCTION(ob_inflatehandler)
+{
+ char *data;
+ int data_len;
+ long mode;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
+ RETURN_FALSE;
+ }
+
+ http_ob_inflatehandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
+ Z_TYPE_P(return_value) = Z_STRVAL_P(return_value) ? IS_STRING : IS_NULL;
+}
+/* }}} */
+
#endif /* HTTP_HAVE_ZLIB */
/* }}} */
#include "php_http_api.h"
#include "php_http_headers_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#ifndef HTTP_DBG_NEG
# define HTTP_DBG_NEG 0
#endif
#include "php_http_api.h"
#include "php_http_info_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
PHP_HTTP_API void _http_info_default_callback(void **nothing, HashTable **headers, http_info *info TSRMLS_DC)
{
zval array;
#include "php_http_send_api.h"
#include "php_http_url_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#define http_message_info_callback _http_message_info_callback
static void _http_message_info_callback(http_message **message, HashTable **headers, http_info *info TSRMLS_DC)
{
# endif
#endif
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpMessage, method, ret_ref, req_args)
#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpMessage, method, ret_ref)
#define HTTP_MESSAGE_ME(method, visibility) PHP_ME(HttpMessage, method, HTTP_ARGS(HttpMessage, method), visibility)
# include "php_http_request_object.h"
#endif
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
/* {{{ cruft for thread safe SSL crypto locks */
#if defined(ZTS) && defined(HTTP_HAVE_SSL)
# ifdef PHP_WIN32
#include "php_http_url_api.h"
#include "php_http_request_body_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
/* {{{ http_request_body *http_request_body_new() */
PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t size, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
{
# include "php_http_request_object.h"
#endif
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
/* {{{ char *http_request_methods[] */
static const char *const http_request_methods[] = {
"UNKNOWN",
#include "php_http_request_pool_api.h"
#include "php_http_url_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, ret_ref, req_args)
#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpRequest, method, ret_ref)
#define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
# define HTTP_DEBUG_REQPOOLS 0
#endif
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#ifndef HAVE_CURL_MULTI_STRERROR
# define curl_multi_strerror(dummy) "unknown error"
#endif
#include "php_http_response_object.h"
#include "php_http_send_api.h"
-
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#define GET_STATIC_PROP(n) *GET_STATIC_PROP_EX(http_response_object_ce, n)
#define UPD_STATIC_PROP(t, n, v) UPD_STATIC_PROP_EX(http_response_object_ce, t, n, v)
#define SET_STATIC_PROP(n, v) SET_STATIC_PROP_EX(http_response_object_ce, n, v)
}
/* gzip */
- HTTP_G(send).gzip_encoding = zval_is_true(GET_STATIC_PROP(gzip));
+ HTTP_G(send).deflate.encoding = zval_is_true(GET_STATIC_PROP(gzip));
/* start ob */
php_start_ob_buffer(NULL, HTTP_G(send).buffer_size, 0 TSRMLS_CC);
#include "php_http_headers_api.h"
#include "php_http_send_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#define http_flush(d, l) _http_flush((d), (l) TSRMLS_CC)
/* {{{ static inline void http_flush() */
static inline void _http_flush(const char *data, size_t data_len TSRMLS_DC)
int encoding;
if ((encoding = http_encoding_response_start(content_length))) {
- //DebugBreak();
#ifdef HTTP_HAVE_ZLIB
*buffer = http_encoding_deflate_stream_init(NULL,
(encoding == HTTP_ENCODING_GZIP) ?
#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).gzip_encoding) {
+ if (HTTP_G(send).deflate.encoding) {
#ifdef HTTP_HAVE_ZLIB
char *encoded;
size_t encoded_len;
#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).gzip_encoding) {
+ if (HTTP_G(send).deflate.encoding) {
#ifdef HTTP_HAVE_ZLIB
char *encoded = NULL;
size_t encoded_len = 0;
#include "php_http_api.h"
#include "php_http_url_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
PHP_HTTP_API char *_http_absolute_url(const char *url TSRMLS_DC)
{
char *abs = estrdup(url);
extern int http_module_number;
+ZEND_EXTERN_MODULE_GLOBALS(http);
+
ZEND_BEGIN_MODULE_GLOBALS(http)
struct _http_globals_etag {
char *content_type;
char *unquoted_etag;
time_t last_modified;
- int gzip_encoding;
+ struct _http_globals_send_deflate {
+ zend_bool start_auto;
+ long start_flags;
+ int encoding;
+ void *stream;
+ } deflate;
+ struct _http_globals_send_inflate {
+ zend_bool start_auto;
+ long start_flags;
+ void *stream;
+ } inflate;
} send;
struct _http_globals_request {
#ifdef HTTP_HAVE_ZLIB
PHP_FUNCTION(http_deflate);
PHP_FUNCTION(http_inflate);
+PHP_FUNCTION(ob_deflatehandler);
+PHP_FUNCTION(ob_inflatehandler);
#endif
PHP_FUNCTION(http_support);
# include "ext/hash/php_hash.h"
#endif
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
#define http_etag_digest(d, l) _http_etag_digest((d), (l))
static inline char *_http_etag_digest(const unsigned char *digest, int len)
{
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 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);
#ifdef HTTP_HAVE_ZLIB
extern PHP_MINIT_FUNCTION(http_encoding);
+extern PHP_RINIT_FUNCTION(http_encoding);
+extern PHP_RSHUTDOWN_FUNCTION(http_encoding);
/* 100% compression should be fairly good */
#define HTTP_ENCODING_MAXTRY 100
void *storage;
} http_encoding_stream;
-#define http_encoding_deflate(f, d, dl, r, rl) _http_encoding_deflate((f), (d), (dl), (r), (rl) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC);
-#define http_encoding_inflate(d, dl, r, rl) _http_encoding_inflate((d), (dl), (r), (rl) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC);
-
-#define http_encoding_deflate_stream_init(s, f) _http_encoding_deflate_stream_init((s), (f) TSRMLS_CC)
-PHP_HTTP_API http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC);
-#define http_encoding_deflate_stream_update(s, d, dl, e, el) _http_encoding_deflate_stream_update((s), (d), (dl), (e), (el) TSRMLS_CC)
-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 TSRMLS_DC);
-#define http_encoding_deflate_stream_flush(s, e, el) _http_encoding_deflate_stream_flush((s), (e), (el) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC);
-#define http_encoding_deflate_stream_finish(s, e, el) _http_encoding_deflate_stream_finish((s), (e), (el) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC);
+#define http_encoding_deflate(f, d, dl, r, rl) _http_encoding_deflate((f), (d), (dl), (r), (rl) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+#define http_encoding_inflate(d, dl, r, rl) _http_encoding_inflate((d), (dl), (r), (rl) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+
+#define http_encoding_deflate_stream_init(s, f) _http_encoding_deflate_stream_init((s), (f) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+#define http_encoding_deflate_stream_update(s, d, dl, e, el) _http_encoding_deflate_stream_update((s), (d), (dl), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+#define http_encoding_deflate_stream_flush(s, e, el) _http_encoding_deflate_stream_flush((s), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+#define http_encoding_deflate_stream_finish(s, e, el) _http_encoding_deflate_stream_finish((s), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
#define http_encoding_deflate_stream_dtor(s) _http_encoding_deflate_stream_dtor((s) TSRMLS_CC)
PHP_HTTP_API void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC);
#define http_encoding_deflate_stream_free(s) _http_encoding_deflate_stream_free((s) TSRMLS_CC)
PHP_HTTP_API void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC);
-#define http_encoding_inflate_stream_init(s, f) _http_encoding_inflate_stream_init((s), (f) TSRMLS_CC)
-PHP_HTTP_API http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC);
-#define http_encoding_inflate_stream_update(s, d, dl, e, el) _http_encoding_inflate_stream_update((s), (d), (dl), (e), (el) TSRMLS_CC)
-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 TSRMLS_DC);
-#define http_encoding_inflate_stream_flush(s, d, dl) _http_encoding_inflate_stream_flush((s), (d), (dl) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC);
-#define http_encoding_inflate_stream_finish(s, e, el) _http_encoding_inflate_stream_finish((s), (e), (el) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC);
+#define http_encoding_inflate_stream_init(s, f) _http_encoding_inflate_stream_init((s), (f) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+#define http_encoding_inflate_stream_update(s, d, dl, e, el) _http_encoding_inflate_stream_update((s), (d), (dl), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+#define http_encoding_inflate_stream_flush(s, d, dl) _http_encoding_inflate_stream_flush((s), (d), (dl) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
+#define http_encoding_inflate_stream_finish(s, e, el) _http_encoding_inflate_stream_finish((s), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
+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);
#define http_encoding_inflate_stream_dtor(s) _http_encoding_inflate_stream_dtor((s) TSRMLS_CC)
PHP_HTTP_API void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC);
#define http_encoding_inflate_stream_free(s) _http_encoding_inflate_stream_free((s) TSRMLS_CC)
PHP_HTTP_API void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC);
+#define http_ob_deflatehandler(o, ol, h, hl, m) _http_ob_deflatehandler((o), (ol), (h), (hl), (m) TSRMLS_CC)
+void _http_ob_deflatehandler(char *, uint, char **, uint *, int TSRMLS_DC);
+
+#define http_ob_inflatehandler(o, ol, h, hl, m) _http_ob_inflatehandler((o), (ol), (h), (hl), (m) TSRMLS_CC)
+void _http_ob_inflatehandler(char *, uint, char **, uint *, int TSRMLS_DC);
#endif /* HTTP_HAVE_ZLIB */
#endif
+++ /dev/null
---TEST--
-PHPUnit HttpResponse
---SKIPIF--
-<?php
-include 'skip.inc';
-checkcls('HttpResponse');
-skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
-?>
---FILE--
-<?php
-echo "-TEST\n";
-
-error_reporting(E_ALL);
-ini_set('html_errors', 0);
-
-require_once 'PHPUnit2/Framework/TestSuite.php';
-require_once 'PHPUnit2/Framework/TestCase.php';
-require_once 'PHPUnit2/TextUI/ResultPrinter.php';
-
-class HttpResponseTest extends PHPUnit2_Framework_TestCase
-{
- function test_setHeader()
- {
- }
-
- function test_getHeader()
- {
- }
-
- function test_setETag()
- {
- }
-
- function test_getETag()
- {
- }
-
- function test_setLastModified()
- {
- }
-
- function test_getLastModified()
- {
- }
-
- function test_setContentDisposition()
- {
- }
-
- function test_getContentDisposition()
- {
- }
-
- function test_setContentType()
- {
- }
-
- function test_getContentType()
- {
- }
-
- function test_guessContentType()
- {
- }
-
- function test_setCache()
- {
- }
-
- function test_getCache()
- {
- }
-
- function test_setCacheControl()
- {
- }
-
- function test_getCacheControl()
- {
- }
-
- function test_setGzip()
- {
- }
-
- function test_getGzip()
- {
- }
-
- function test_setThrottleDelay()
- {
- }
-
- function test_getThrottleDelay()
- {
- }
-
- function test_setBufferSize()
- {
- }
-
- function test_getBufferSize()
- {
- }
-
- function test_setData()
- {
- }
-
- function test_getData()
- {
- }
-
- function test_setFile()
- {
- }
-
- function test_getFile()
- {
- }
-
- function test_setStream()
- {
- }
-
- function test_getStream()
- {
- }
-
- function test_send()
- {
- }
-
- function test_capture()
- {
- }
-
- function test_redirect()
- {
- }
-
- function test_status()
- {
- }
-
- function test_getRequestHeaders()
- {
- }
-
- function test_getRequestBody()
- {
- }
-
-
-}
-
-$s = new PHPUnit2_Framework_TestSuite('HttpResponseTest');
-$p = new PHPUnit2_TextUI_ResultPrinter();
-$p->printResult($s->run(), 0);
-
-echo "Done\n";
-?>
---EXPECTF--
-%sTEST
-
-
-Time: 0
-
-OK (33 tests)
-Done
function test_buildUrl()
{
$_SERVER['SERVER_NAME'] = 'www.example.com';
- $this->assertEquals('http://www.example.com/test.php?foo=bar', HttpUtil::buildUrl('/test.php?foo=bar', null, null, 80));
- $this->assertEquals('https://www.example.com/', HttpUtil::buildUrl('/', 'https'));
- $this->assertEquals('ftp://ftp.example.com/pub', HttpUtil::buildUrl('/pub', null, 'ftp.example.com', 21));
+ $this->assertEquals('http://www.example.com/test.php?foo=bar', HttpUtil::buildUrl('/test.php?foo=bar', array('port' => 80)));
+ $this->assertEquals('https://www.example.com/', HttpUtil::buildUrl('/', array('scheme' => 'https')));
+ $this->assertEquals('ftp://ftp.example.com/pub', HttpUtil::buildUrl('/pub', array('host' => 'ftp.example.com', 'port' => 21)));
}
function test_negotiateLanguage()