From: Michael Wallner Date: Fri, 26 Aug 2005 11:13:15 +0000 (+0000) Subject: - update docs X-Git-Tag: RELEASE_0_12_0~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=674546ff295b792737b06e34f77c7f87f8fe534b;p=m6w6%2Fext-http - update docs --- diff --git a/docs/functions.html b/docs/functions.html index e44c943..16dd0a5 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -72,7 +72,7 @@ The supported parameter is expected to be an array having
the supported languages as array values.

Example:


-<?php
$langs
= array(
        
'en-US',// default
        
'fr',
        
'fr-FR',
        
'de',
        
'de-DE',
        
'de-AT',
        
'de-CH',
);
include
'./langs/'. http_negotiate_language($langs) .'.php';
?>
+<?php
$langs 
= array(
        
'en-US',// default
        
'fr',
        
'fr-FR',
        
'de',
        
'de-DE',
        
'de-AT',
        
'de-CH',
);
include 
'./langs/'http_negotiate_language($langs) .'.php';
?>



@@ -88,7 +88,7 @@ The supported parameter is expected to be an array having
the supported charsets as array values.

Example:


-<?php
$charsets
= array(
        
'iso-8859-1', // default
        
'iso-8859-2',
        
'iso-8859-15',
        
'utf-8'
);
$pref = http_negotiate_charset($charsets);
if (!
strcmp($pref, 'iso-8859-1')) {
        
iconv_set_encoding('internal_encoding', 'iso-8859-1');
        
iconv_set_encoding('output_encoding', $pref);
        
ob_start('ob_iconv_handler');
}
?>
+<?php
$charsets 
= array(
        
'iso-8859-1'// default
        
'iso-8859-2',
        
'iso-8859-15',
        
'utf-8'
);
$pref http_negotiate_charset($charsets);
if (!
strcmp($pref'iso-8859-1')) {
        
iconv_set_encoding('internal_encoding''iso-8859-1');
        
iconv_set_encoding('output_encoding'$pref);
        
ob_start('ob_iconv_handler');
}
?>



@@ -132,7 +132,7 @@ a "304 Not Modified" status code is issued.

Use with http_send() API.

Example:


-<?php
// ~ 20 kbyte/s
# http_throttle(1, 20000);
# http_throttle(0.5, 10000);
# http_throttle(0.1, 2000);
http_send_file('document.pdf');
?>
+<?php
// ~ 20 kbyte/s
# http_throttle(1, 20000);
# http_throttle(0.5, 10000);
# http_throttle(0.1, 2000);
http_send_file('document.pdf');
?>



@@ -158,10 +158,9 @@ if the client doesn't redirect immediatly.

string http_chunked_decode(string encoded)

This function decodes a string that was HTTP-chunked encoded.
Returns false on failure.

-

array http_split_response(string http_response)

-

This function splits an HTTP response into an array with headers and the
-content body. The returned array may look simliar to the following example:


-<?php
array(
    
0 => array(
        
'Response Status' => '200 Ok',
        
'Content-Type' => 'text/plain',
        
'Content-Language' => 'en-US'
    
),
    
1 => "Hello World!"
);
?>
+

object http_parse_message(string message)

+

Parses (a) http_message(s) into a simple recursive object structure:


+<?php
print_r
(http_parse_message(http_get(URL, array('redirect' => 3)));

stdClass object
(
    [
type] => 2
    
[httpVersion] => 1.1
    
[responseCode] => 200
    
[headers] => Array 
        (
            [
Content-Length] => 3
            
[Server] => Apache
        
)
    [
body]  => Hi!
    [
parentMessage] => stdClass object
    
(
        [
type] => 2
        
[httpVersion] => 1.1
        
[responseCode] => 302
        
[headers] => Array 
            (
                [
Content-Length] => 0
                
[Location] => ...
            )
        [
body]  => 
        [
parentMessage] => ...
    )
)
?>



@@ -207,7 +206,7 @@ array where the following keys will be recognized:

 - redirect:
  - connecttimeout:   int, seconds the connect may take
- onprogress: mixed, progress callback

The optional third parameter will be filled with some additional information
in form af an associative array, if supplied, like the following example:


-<?php
array (
    
'effective_url' => 'http://localhost',
    
'response_code' => 403,
    
'total_time' => 0.017,
    
'namelookup_time' => 0.013,
    
'connect_time' => 0.014,
    
'pretransfer_time' => 0.014,
    
'size_upload' => 0,
    
'size_download' => 202,
    
'speed_download' => 11882,
    
'speed_upload' => 0,
    
'header_size' => 145,
    
'request_size' => 62,
    
'ssl_verifyresult' => 0,
    
'filetime' => -1,
    
'content_length_download' => 202,
    
'content_length_upload' => 0,
    
'starttransfer_time' => 0.017,
    
'content_type' => 'text/html; charset=iso-8859-1',
    
'redirect_time' => 0,
    
'redirect_count' => 0,
    
'private' => '',
    
'http_connectcode' => 0,
    
'httpauth_avail' => 0,
    
'proxyauth_avail' => 0,
)
?>
+<?php
array (
    
'effective_url' => 'http://localhost',
    
'response_code' => 403,
    
'total_time' => 0.017,
    
'namelookup_time' => 0.013,
    
'connect_time' => 0.014,
    
'pretransfer_time' => 0.014,
    
'size_upload' => 0,
    
'size_download' => 202,
    
'speed_download' => 11882,
    
'speed_upload' => 0,
    
'header_size' => 145,
    
'request_size' => 62,
    
'ssl_verifyresult' => 0,
    
'filetime' => -1,
    
'content_length_download' => 202,
    
'content_length_upload' => 0,
    
'starttransfer_time' => 0.017,
    
'content_type' => 'text/html; charset=iso-8859-1',
    
'redirect_time' => 0,
    
'redirect_count' => 0,
    
'http_connectcode' => 0,
    
'httpauth_avail' => 0,
    
'proxyauth_avail' => 0,
)
?>



@@ -216,7 +215,7 @@ in form af an associative array, if supplied, like the following example:

Performs an HTTP HEAD request on the suppied url.
Returns the HTTP response as string.
See http_get() for a full list of available options.

-

string http_post_data(string url, string data[, array options[, &info]])

+

string http_post_data(string url, string data[, array options[, array &info]])

Performs an HTTP POST request, posting data.
Returns the HTTP response as string.
See http_get() for a full list of available options.

@@ -240,20 +239,6 @@ See http_get() for a full list of available options.

Check if a request method is registered (or available by default).

string http_request_method_name(long method)

Get the literal string representation of a standard or registered request method.

-

bool http_auth_basic(string user, string pass[, string realm = "Restricted"])

-

Example:


-<?php
if (!http_auth_basic('mike', 's3c|r3t')) {
    die(
'<h1>Authorization failed!</h1>');
}
?>
-

-

-
-

-

bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])

-

Example:


-<?php
function auth_cb($user, $pass)
{
    global
$db;
    
$query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
    if (
strlen($realpass = $db->getOne($query)) {
        return
$pass === $realpass;
    }
    return
false;
}
if (!
http_auth_basic_cb('auth_cb')) {
    die(
'<h1>Authorization failed</h1>');
}
?>
-

-

-
-

string http_build_query(mixed formdata [, string prefix[, string arg_separator]])

Generates a form-encoded query string from an associative array or object.


@@ -312,30 +297,28 @@ Returns false if version is invalid (1.0 and 1.1).

and POST (including posting files) HTTP requests.

void HttpRequest::__destruct()

Destroys the HttpRequest object.

-

bool HttpRequest::setOptions(array options)

+

bool HttpRequest::setOptions([array options])

Set the request options to use. See http_get() for a full list of available options.

array HttpRequest::getOptions()

-

Get current set options.

-

void HttpRequest::unsetOptions()

-

Unset all options/headers/cookies.

-

bool HttpRequest::setSslOptions(array options)

+

Get currently set options.

+

bool HttpRequest::setSslOptions([array options])

+

Set SSL options.

+

bool HttpRequest::addSslOptions(array options)

Set additional SSL options.

array HttpRequest::getSslOtpions()

Get previously set SSL options.

-

void HttpRequest::unsetSslOptions()

-

Unset previously set SSL options.

bool HttpRequest::addHeaders(array headers)

Add request header name/value pairs.

+

bool HttpRequest::setHeaders([array headers])

+

Set request header name/value pairs.

array HttpRequest::getHeaders()

Get previously set request headers.

-

void HttpRequest::unsetHeaders()

-

Unset previously set request headers.

+

bool HttpRequest::setCookies([array cookies])

+

Set cookies.

bool HttpRequest::addCookies(array cookies)

Add cookies.

array HttpRequest::getCookies()

Get previously set cookies.

-

void HttpRequest::unsetCookies()

-

bool HttpRequest::setUrl(string url)

Set the request URL.

string HttpRequest::getUrl()

@@ -350,7 +333,7 @@ and POST (including posting files) HTTP requests.

Use this only if you know what you're doing.

string HttpRequest::getContentType()

Get the previously content type.

-

bool HttpRequest::setQueryData(mixed query_data)

+

bool HttpRequest::setQueryData([mixed query_data])

Set the URL query parameters to use.
Overwrites previously set query parameters.
Affects any request types.

@@ -359,41 +342,29 @@ Affects any request types.

bool HttpRequest::addQueryData(array query_params)

Add parameters to the query parameter list.
Affects any request type.

-

void HttpRequest::unsetQueryData()

-

Clean the query parameters.
-Affects any request type.

bool HttpRequest::addPostFields(array post_data)

Adds POST data entries.
Affects only POST requests.

-

bool HttpRequest::setPostFields(array post_data)

+

bool HttpRequest::setPostFields([array post_data])

Set the POST data entries.
Overwrites previously set POST data.
Affects only POST requests.

array HttpRequest::getPostFields()

Get previously set POST data.

-

void HttpRequest::unsetPostFields()

-

Clean POST data entires.
-Affects only POST requests.

bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])

Add a file to the POST request.
Affects only POST requests.

-

bool HttpRequest::setPostFiles(array post_files)

+

bool HttpRequest::setPostFiles([array post_files])

Set files to post.
Overwrites previously set post files.
Affects only POST requests.

array HttpRequest::getPostFiles()

Get all previously added POST files.

-

void HttpRequest::unsetPostFiles()

-

Unset the POST files list.
-Affects only POST requests.

-

bool HttpRequest::SetPutFile(string file)

+

bool HttpRequest::setPutFile([string file])

Set file to put.
Affects only PUT requests.

string HttpRequest::getPutFile()

Get previously set put file.

-

void HttpRequest::unsetPutFile()

-

Unset file to put.
-Affects only PUT requests.

array HttpRequest::getResponseData()

Get all response data after the request has been sent.

mixed HttpRequest::getResponseHeader([string name])

@@ -411,14 +382,14 @@ See http_get() for a full list of returned info.

Get the full response as HttpMessage object.

HttpMessage HttpRequest::getRequestMessage()

Get sent HTTP message.

-

bool HttpRequest::send()

+

HttpMessage HttpRequest::send()

Send the HTTP request.

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'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;
}
?>

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');
if (
$r->send()) {
    echo
$r->getResponseBody();
}
?>
+<?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;
}
?>



@@ -431,7 +402,7 @@ GET example:


able to send several HttpRequests in parallel.

Example:


-<?php
try {
    
$pool = new HttpRequestPool(
        new
HttpRequest('http://www.google.com/', HTTP_HEAD),
        new
HttpRequest('http://www.php.net/', HTTP_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;
}
?>
+<?php
try {
    
$pool = new HttpRequestPool(
        new 
HttpRequest('http://www.google.com/'HTTP_HEAD),
        new 
HttpRequest('http://www.php.net/'HTTP_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;
}
?>



@@ -447,17 +418,15 @@ NOTE: set all options prior attaching!

Detach an HttpRequest object from this HttpRequestPool.

bool HttpRequestPool::send()

Send all attached HttpRequest objects in parallel.

-

protected bool HttpRequestPool::socketSend()

+

protected bool HttpRequestPool::socketSend()

Usage:


-<?php
    
while ($pool->socketSend()) {
        
do_something_else();
        if (!
$pool->socketSelect()) {
            die(
'Socket error');
        }
    }
    
$pool->socketRead();
?>
+<?php
    
while ($pool->socketPerform()) {
        
do_something_else();
        if (!
$pool->socketSelect()) {
            die(
'Socket error');
        }
    }
?>



protected bool HttpRequestPool::socketSelect()

-

See HttpRequestPool::socketSend().

-

protected void HttpRequestPool::socketRead()

-

See HttpRequestPool::socketSend().

+

See HttpRequestPool::socketPerform().

bool HttpRequestPool::valid()

Implements Iterator::valid().

HttpRequest HttpRequestPool::current()

@@ -470,6 +439,10 @@ NOTE: set all options prior attaching!

Implements Iterator::rewind().


http_response_object.c

+

static bool HttpResponse::setHeader(string name, mixed value[, bool replace = true)

+

+

static mixed HttpResponse::getHeader([string name])

+

static bool HttpResponse::setCache(bool cache)

Whether it sould be attempted to cache the entitity.
This will result in necessary caching headers and checks of clients
@@ -481,7 +454,7 @@ to something more appropriate than "no-cache"!

static bool HttpResponse::getCache()

Get current caching setting.

static bool HttpResponse::setGzip(bool gzip)

-

Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET.

+

Enable on-thy-fly gzipping of the sent entity.

static bool HttpResponse::getGzip()

Get current gzipping setting.

static bool HttpResponse::setCacheControl(string control[, long max_age = 0])

@@ -502,12 +475,16 @@ will show the user a "Save As..." popup.

static bool HttpResponse::setETag(string etag)

Set a custom ETag. Use this only if you know what you're doing.

static string HttpResponse::getETag()

-

Get the previously set custom ETag.

-

static void HttpResponse::setThrottleDelay(double seconds)

+

Get calculated or previously set custom ETag.

+

static bool HttpResponse::setLastModified(long timestamp)

+

Set a custom Last-Modified date.

+

static HttpResponse::getLastModified()

+

Get calculated or previously set custom Last-Modified date.

+

static bool HttpResponse::setThrottleDelay(double seconds)

static double HttpResponse::getThrottleDelay()

-

static void HttpResponse::setBufferSize(long bytes)

+

static bool HttpResponse::setBufferSize(long bytes)

static long HttpResponse::getBufferSize()

@@ -527,7 +504,7 @@ will show the user a "Save As..." popup.

Finally send the entity.

Example:


-<?php
HttpResponse
::setCache(true);
HttpResponse::setContentType('application/pdf');
HttpResponse::setContentDisposition("$user.pdf", false);
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
?>
+<?php
HttpResponse
::setCache(true);
HttpResponse::setContentType('application/pdf');
HttpResponse::setContentDisposition("$user.pdf"false);
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
?>



@@ -536,13 +513,13 @@ Example:


Capture script output.

Example:


-<?php
HttpResponse
::setCache(true);
HttpResponse::capture();
// script follows
?>
+<?php
HttpResponse
::setCache(true);
HttpResponse::capture();
// script follows
// note that you need to call
HttpResponse::send();
// at the end of the script unless 
// you use PHP-5.1 or greater
?>




-

Generated at: Mon, 01 Aug 2005 09:46:36 +0200

+

Generated at: Fri, 26 Aug 2005 11:08:03 +0000

diff --git a/http_response_object.c b/http_response_object.c index 5e588ea..666040b 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -335,7 +335,7 @@ PHP_METHOD(HttpResponse, getCache) /* {{{ proto static bool HttpResponse::setGzip(bool gzip) * - * Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET. + * Enable on-thy-fly gzipping of the sent entity. */ PHP_METHOD(HttpResponse, setGzip) {