From 419ba9235752d56f15b393fc7969316978c6c721 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 9 Dec 2005 16:56:24 +0000 Subject: [PATCH] - lotta changes asked by Ilia # had not really time to test, need to rush :) --- docs/functions.html | 15 +++++++-------- http_encoding_api.c | 5 +++++ http_message_api.c | 21 +++++++++++++++++---- http_request_api.c | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/docs/functions.html b/docs/functions.html index b815071..fa3d1c5 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -81,7 +81,7 @@ The host will be taken either from the Host HTTP header of the client
the SERVER_NAME or just localhost if prior are not available.
If a port is pecified in either the url or as sperate parameter,
it will be added if it differs from te default port for HTTP(S).

-

Returns the absolute URI as string.

+

Returns the absolute URI as string on success or false on failure.

Examples:


<?php
$uri 
http_build_uri("page.php""https"NULL488);
?>

@@ -569,7 +569,7 @@ pairs to add.

bool HttpRequest::setMethod(int request_method)

Set the request method.

Expects an int as parameter specifying the request method to use.
-In PHP 5.1+ HttpRequest::METH, otherwise the HTTP_METH constants can be used.

+In PHP 5.1+ HttpRequest::METH_*, otherwise the HTTP_METH_* constants can be used.

Returns TRUE on success, or FALSE on failure.

int HttpRequest::getMethod()

Get the previously set request method.

@@ -745,11 +745,11 @@ HttpRequest::getResponse*() methods.

Throws HttpRuntimeException, HttpRequestException,
HttpMalformedHeaderException, HttpEncodingException.

GET example:


-<?php
$r 
= new HttpRequest('http://example.com/feed.rss'HTTP_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
    
$r->send();
    if (
$r->getResponseCode() == 200) {
        
file_put_contents('local.rss'$r->getResponseBody());
   }
} catch (
HttpException $ex) {
    echo 
$ex;
}
?>
+<?php
$r 
= new HttpRequest('http://example.com/feed.rss'HttpRequest::METH_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
    
$r->send();
    if (
$r->getResponseCode() == 200) {
        
file_put_contents('local.rss'$r->getResponseBody());
   }
} catch (
HttpException $ex) {
    echo 
$ex;
}
?>

POST example:


-<?php
$r 
= new HttpRequest('http://example.com/form.php'HTTP_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike''pass' => 's3c|r3t'));
$r->addPostFile('image''profile.jpg''image/jpeg');
try {
    echo 
$r->send()->getBody();
} catch (
HttpException $ex) {
    echo 
$ex;
}
?>
+<?php
$r 
= new HttpRequest('http://example.com/form.php'HttpRequest::METH_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike''pass' => 's3c|r3t'));
$r->addPostFile('image''profile.jpg''image/jpeg');
try {
    echo 
$r->send()->getBody();
} catch (
HttpException $ex) {
    echo 
$ex;
}
?>


@@ -762,7 +762,7 @@ able to send several HttpRequests in parallel.

object while you're using the implemented Interator interface.

Accepts virtual infinite optional parameters each referencing an
HttpRequest object.

-

Throws HttpRequestException, HttpRequestPoolException, HttpInvalidParamException.

+

Throws HttpRequestPoolException (HttpRequestException, HttpInvalidParamException).

Example:


<?php
try {
    
$pool = new HttpRequestPool(
        new 
HttpRequest('http://www.google.com/'HttpRequest::METH_HEAD),
        new 
HttpRequest('http://www.php.net/'HttpRequest::METH_HEAD)
    );
    
$pool->send();
    foreach(
$pool as $request) {
        
printf("%s is %s (%d)\n",
            
$request->getUrl(),
            
$request->getResponseCode() ? 'alive' 'not alive',
            
$request->getResponseCode()
        );
    }
} catch (
HttpException $e) {
    echo 
$e;
}
?>

@@ -788,8 +788,7 @@ HttpRequestPool object.

bool HttpRequestPool::send()

Send all attached HttpRequest objects in parallel.

Returns TRUE on success, or FALSE on failure.

-

Throws HttpSocketException, HttpRequestException,
-HttpRequestPoolException, HttpMalformedHeaderException.

+

Throws HttpRequestPoolException (HttpSocketException, HttpRequestException, HttpMalformedHeaderException).

protected bool HttpRequestPool::socketPerform()

Returns TRUE until each request has finished its transaction.

Usage:


@@ -1201,7 +1200,7 @@ http.cache_log is set.

-

Generated at: Mon, 21 Nov 2005 16:56:18 +0100

+

Generated at: Fri, 09 Dec 2005 13:56:42 +0100

diff --git a/http_encoding_api.c b/http_encoding_api.c index 7b726c8..f5c0494 100644 --- a/http_encoding_api.c +++ b/http_encoding_api.c @@ -472,6 +472,11 @@ PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, ch *decoded_len = http_finish_buffer(Z.total_out, decoded); return SUCCESS; } + } else { + inflateEnd(&Z); + if (status == Z_OK) { + status = Z_BUF_ERROR; + } } } } while (++max < HTTP_ENCODING_MAXTRY && status == Z_BUF_ERROR); diff --git a/http_message_api.c b/http_message_api.c index d9b33d1..ac056ad 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -243,6 +243,12 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char decoded_len = Z_STRLEN(retval); \ } \ } + +# define REMEMBER_ENCODING() \ + if (decoded) { \ + ZVAL_ADDREF(c); \ + zend_hash_add(&msg->hdrs, "X-Original-Content-Encoding", sizeof("X-Original-Content-Encoding"), (void *) &c, sizeof(zval *), NULL); \ + } if (!strcasecmp(Z_STRVAL_P(c), "gzip") || !strcasecmp(Z_STRVAL_P(c), "x-gzip")) { # ifdef HTTP_HAVE_ZLIB @@ -251,6 +257,7 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char ZVAL_STRINGL(&arg, PHPSTR_VAL(msg) + 10, PHPSTR_LEN(msg) - 18, 0); DECODE_WITH_EXT_ZLIB(); # endif /* HTTP_HAVE_ZLIB */ + REMEMBER_ENCODING(); } else if (!strcasecmp(Z_STRVAL_P(c), "deflate")) { # ifdef HTTP_HAVE_ZLIB http_encoding_inflate(PHPSTR_VAL(msg), PHPSTR_LEN(msg), &decoded, &decoded_len); @@ -258,10 +265,11 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char ZVAL_STRINGL(&arg, PHPSTR_VAL(msg), PHPSTR_LEN(msg), 0); DECODE_WITH_EXT_ZLIB(); # endif /* HTTP_HAVE_ZLIB */ + REMEMBER_ENCODING(); } if (decoded) { - zval *len; + zval *len, **original_len; char *tmp; int tmp_len; @@ -270,9 +278,14 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char ZVAL_STRINGL(len, tmp, tmp_len, 0); zend_hash_del(&msg->hdrs, "Content-Encoding", sizeof("Content-Encoding")); - zend_hash_del(&msg->hdrs, "Content-Length", sizeof("Content-Length")); - zend_hash_add(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL); - + if (zend_hash_find(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void **) &original_len) == SUCCESS) { + ZVAL_ADDREF(*original_len); + zend_hash_add(&msg->hdrs, "X-Original-Content-Length", sizeof("X-Original-Content-Length"), (void *) original_len, sizeof(zval *), NULL); + zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL); + } else { + zend_hash_add(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL); + } + phpstr_dtor(PHPSTR(msg)); PHPSTR(msg)->data = decoded; PHPSTR(msg)->used = decoded_len; diff --git a/http_request_api.c b/http_request_api.c index f02aa18..c43aa1a 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -468,7 +468,7 @@ PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char /* compress, empty string enables all supported if libcurl was build with zlib support */ if ((zoption = http_curl_getopt(options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) { #if defined(HTTP_HAVE_ZLIB) || defined(HAVE_ZLIB) - HTTP_CURL_OPT(ENCODING, "gzip;q=1.0, deflate;q=0.5, *;q=0"); + HTTP_CURL_OPT(ENCODING, "gzip;q=1.0, deflate;q=0.5, *;q=0.1"); #else HTTP_CURL_OPT(ENCODING, ""); #endif -- 2.30.2