[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/ -> HTTPClient.php (summary)

HTTP Client

Author: Andreas Goetz
License: GPL 2 (http://www.gnu.org/licenses/gpl.html)
File Size: 943 lines (35 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 3 classes

HTTPClientException:: (0 methods):

HTTPClient:: (19 methods):
  __construct()
  get()
  dget()
  post()
  sendRequest()
  _ssltunnel()
  _sendData()
  _readData()
  _readLine()
  _debug()
  _debug_html()
  _debug_text()
  _time()
  _parseHeaders()
  _buildHeaders()
  _getCookies()
  _postEncode()
  _postMultipartEncode()
  _uniqueConnectionId()

DokuHTTPClient:: (2 methods):
  __construct()
  sendRequest()


Class: HTTPClientException  - X-Ref

Class HTTPClientException

Class: HTTPClient  - X-Ref

This class implements a basic HTTP client

It supports POST and GET, Proxy usage, basic authentication,
handles cookies and referers. It is based upon the httpclient
function from the VideoDB project.

__construct()   X-Ref
Constructor.

author: Andreas Gohr <andi@splitbrain.org>

get($url,$sloppy304=false)   X-Ref
Simple function to do a GET request

Returns the wanted page or false on an error;

param: string $url       The URL to fetch
param: bool   $sloppy304 Return body on 304 not modified
author: Andreas Gohr <andi@splitbrain.org>
return: false|string  response body, false on error

dget($url,$data,$sloppy304=false)   X-Ref
Simple function to do a GET request with given parameters

Returns the wanted page or false on an error.

This is a convenience wrapper around get(). The given parameters
will be correctly encoded and added to the given base URL.

param: string $url       The URL to fetch
param: array  $data      Associative array of parameters
param: bool   $sloppy304 Return body on 304 not modified
author: Andreas Gohr <andi@splitbrain.org>
return: false|string  response body, false on error

post($url,$data)   X-Ref
Simple function to do a POST request

Returns the resulting page or false on an error;

param: string $url       The URL to fetch
param: array  $data      Associative array of parameters
author: Andreas Gohr <andi@splitbrain.org>
return: false|string  response body, false on error

sendRequest($url,$data='',$method='GET')   X-Ref
Send an HTTP request

This method handles the whole HTTP communication. It respects set proxy settings,
builds the request headers, follows redirects and parses the response.

Post data should be passed as associative array. When passed as string it will be
sent as is. You will need to setup your own Content-Type header then.

param: string $url    - the complete URL
param: mixed  $data   - the post data either as array or raw data
param: string $method - HTTP Method usually GET or POST.
author: Andreas Goetz <cpuidle@gmx.de>
author: Andreas Gohr <andi@splitbrain.org>
return: bool - true on success

_ssltunnel(&$socket, &$requesturl)   X-Ref
Tries to establish a CONNECT tunnel via Proxy

Protocol, Servername and Port will be stripped from the request URL when a successful CONNECT happened

param: resource &$socket
param: string   &$requesturl
return: bool true if a tunnel was established

_sendData($socket, $data, $message)   X-Ref
Safely write data to a socket

param: resource $socket     An open socket handle
param: string   $data       The data to write
param: string   $message    Description of what is being read
author: Tom N Harris <tnharris@whoopdedo.org>

_readData($socket, $nbytes, $message, $ignore_eof = false)   X-Ref
Safely read data from a socket

Reads up to a given number of bytes or throws an exception if the
response times out or ends prematurely.

param: resource $socket     An open socket handle in non-blocking mode
param: int      $nbytes     Number of bytes to read
param: string   $message    Description of what is being read
param: bool     $ignore_eof End-of-file is not an error if this is set
author: Tom N Harris <tnharris@whoopdedo.org>
return: string

_readLine($socket, $message)   X-Ref
Safely read a \n-terminated line from a socket

Always returns a complete line, including the terminating \n.

param: resource $socket     An open socket handle in non-blocking mode
param: string   $message    Description of what is being read
author: Tom N Harris <tnharris@whoopdedo.org>
return: string

_debug($info,$var=null)   X-Ref
print debug info

Uses _debug_text or _debug_html depending on the SAPI name

param: string $info
param: mixed  $var
author: Andreas Gohr <andi@splitbrain.org>

_debug_html($info, $var=null)   X-Ref
print debug info as HTML

param: string $info
param: mixed  $var

_debug_text($info, $var=null)   X-Ref
prints debug info as plain text

param: string $info
param: mixed  $var

_time()   X-Ref
Return current timestamp in microsecond resolution

return: float

_parseHeaders($string)   X-Ref
convert given header string to Header array

All Keys are lowercased.

param: string $string
author: Andreas Gohr <andi@splitbrain.org>
return: array

_buildHeaders($headers)   X-Ref
convert given header array to header string

param: array $headers
author: Andreas Gohr <andi@splitbrain.org>
return: string

_getCookies()   X-Ref
get cookies as http header string

author: Andreas Goetz <cpuidle@gmx.de>
return: string

_postEncode($data)   X-Ref
Encode data for posting

param: array $data
author: Andreas Gohr <andi@splitbrain.org>
return: string

_postMultipartEncode($data)   X-Ref
Encode data for posting using multipart encoding

param: array $data
author: Andreas Gohr <andi@splitbrain.org>
return: string

_uniqueConnectionId($server, $port)   X-Ref
Generates a unique identifier for a connection.

param: string $server
param: string $port
return: string unique identifier

Class: DokuHTTPClient  - X-Ref

Adds DokuWiki specific configs to the HTTP client

__construct()   X-Ref
Constructor.

author: Andreas Gohr <andi@splitbrain.org>

sendRequest($url,$data='',$method='GET')   X-Ref

param: string $url
param: string|array $data the post data either as array or raw data
param: string $method
return: bool