XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
HTTP_Request2_Adapter_Socket Class Reference
Inheritance diagram for HTTP_Request2_Adapter_Socket:
HTTP_Request2_Adapter

Public Member Functions

 sendRequest (HTTP_Request2 $request)
 
- Public Member Functions inherited from HTTP_Request2_Adapter
 sendRequest (HTTP_Request2 $request)
 

Public Attributes

const REGEXP_TOKEN = '[^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+'
 
const REGEXP_QUOTED_STRING = '"(?>[^"\\\\]+|\\\\.)*"'
 

Protected Member Functions

 connect ()
 
 establishTunnel ()
 
 canKeepAlive ($requestKeepAlive, HTTP_Request2_Response $response)
 
 disconnect ()
 
 handleRedirect (HTTP_Request2 $request, HTTP_Request2_Response $response)
 
 shouldUseServerDigestAuth (HTTP_Request2_Response $response)
 
 shouldUseProxyDigestAuth (HTTP_Request2_Response $response)
 
 parseDigestChallenge ($headerValue)
 
 updateChallenge (&$challenge, $headerValue)
 
 createDigestResponse ($user, $password, $url, &$challenge)
 
 addAuthorizationHeader (&$headers, $requestHost, $requestUrl)
 
 addProxyAuthorizationHeader (&$headers, $requestUrl)
 
 prepareHeaders ()
 
 updateExpectHeader (&$headers)
 
 writeBody ()
 
 readResponse ()
 
 readChunked ($bufferSize)
 
- Protected Member Functions inherited from HTTP_Request2_Adapter
 calculateRequestLength (&$headers)
 

Protected Attributes

 $socket
 
 $serverChallenge
 
 $proxyChallenge
 
 $chunkLength = 0
 
 $redirectCountdown = null
 
 $expect100Continue = false
 
- Protected Attributes inherited from HTTP_Request2_Adapter
 $request
 
 $requestBody
 
 $contentLength
 

Static Protected Attributes

static $sockets = array()
 
static $challenges = array()
 
- Static Protected Attributes inherited from HTTP_Request2_Adapter
static $bodyDisallowed = array('TRACE')
 
static $bodyRequired = array('POST', 'PUT')
 

Detailed Description

Definition at line 40 of file Socket.php.

Member Function Documentation

HTTP_Request2_Adapter_Socket::addAuthorizationHeader ( $headers,
  $requestHost,
  $requestUrl 
)
protected

Adds 'Authorization' header (if needed) to request headers array

Parameters
array&$headersrequest headers
string$requestHostrequest host (needed for digest authentication)
string$requestUrlrequest URL (needed for digest authentication)
Exceptions
HTTP_Request2_NotImplementedException

Definition at line 729 of file Socket.php.

HTTP_Request2_Adapter_Socket::addProxyAuthorizationHeader ( $headers,
  $requestUrl 
)
protected

Adds 'Proxy-Authorization' header (if needed) to request headers array

Parameters
array&$headersrequest headers
string$requestUrlrequest URL (needed for digest authentication)
Exceptions
HTTP_Request2_NotImplementedException

Definition at line 774 of file Socket.php.

HTTP_Request2_Adapter_Socket::canKeepAlive (   $requestKeepAlive,
HTTP_Request2_Response  $response 
)
protected

Checks whether current connection may be reused or should be closed

Parameters
boolean$requestKeepAlivewhether connection could be persistent in the first place
HTTP_Request2_Response$responseresponse object to check
Returns
boolean

Definition at line 372 of file Socket.php.

HTTP_Request2_Adapter_Socket::connect ( )
protected

Connects to the remote server

Returns
bool whether the connection can be persistent
Exceptions
HTTP_Request2_Exception

Definition at line 195 of file Socket.php.

HTTP_Request2_Adapter_Socket::createDigestResponse (   $user,
  $password,
  $url,
$challenge 
)
protected

Creates a value for [Proxy-]Authorization header when using digest authentication

Parameters
string$useruser name
string$passwordpassword
string$urlrequest URL
array&$challengedigest challenge parameters
Returns
string value of [Proxy-]Authorization request header http://tools.ietf.org/html/rfc2617#section-3.2.2

Definition at line 683 of file Socket.php.

HTTP_Request2_Adapter_Socket::disconnect ( )
protected

Disconnects from the remote server

Definition at line 395 of file Socket.php.

HTTP_Request2_Adapter_Socket::establishTunnel ( )
protected

Establishes a tunnel to a secure remote server via HTTP CONNECT request

This method will fail if 'ssl_verify_peer' is enabled. Probably because PHP sees that we are connected to a proxy server (duh!) rather than the server that presents its certificate.

HTTP_Request2_Exception

Definition at line 344 of file Socket.php.

HTTP_Request2_Adapter_Socket::handleRedirect ( HTTP_Request2  $request,
HTTP_Request2_Response  $response 
)
protected

Handles HTTP redirection

This method will throw an Exception if redirect to a non-HTTP(S) location is attempted, also if number of redirects performed already is equal to 'max_redirects' configuration parameter.

Parameters
HTTP_Request2$requestOriginal request
HTTP_Request2_Response$responseResponse containing redirect
Returns
HTTP_Request2_Response Response from a new location
Exceptions
HTTP_Request2_Exception

Definition at line 416 of file Socket.php.

HTTP_Request2_Adapter_Socket::parseDigestChallenge (   $headerValue)
protected

Extracts digest method challenge from (WWW|Proxy)-Authenticate header value

There is a problem with implementation of RFC 2617: several of the parameters are defined as quoted-string there and thus may contain backslash escaped double quotes (RFC 2616, section 2.2). However, RFC 2617 defines unq(X) as just value of quoted-string X without surrounding quotes, it doesn't speak about removing backslash escaping.

Now realm parameter is user-defined and human-readable, strange things happen when it contains quotes:

  • Apache allows quotes in realm, but apparently uses realm value without backslashes for digest computation
  • Squid allows (manually escaped) quotes there, but it is impossible to authorize with either escaped or unescaped quotes used in digest, probably it can't parse the response (?)
  • Both IE and Firefox display realm value with backslashes in the password popup and apparently use the same value for digest

HTTP_Request2 follows IE and Firefox (and hopefully RFC 2617) in quoted-string handling, unfortunately that means failure to authorize sometimes

Parameters
string$headerValuevalue of WWW-Authenticate or Proxy-Authenticate header
Returns
mixed associative array with challenge parameters, false if no challenge is present in header value
Exceptions
HTTP_Request2_NotImplementedExceptionin case of unsupported challenge parameters

Definition at line 600 of file Socket.php.

HTTP_Request2_Adapter_Socket::prepareHeaders ( )
protected

Creates the string with the Request-Line and request headers

Returns
string
Exceptions
HTTP_Request2_Exception

Definition at line 820 of file Socket.php.

HTTP_Request2_Adapter_Socket::readChunked (   $bufferSize)
protected

Reads a part of response body encoded with chunked Transfer-Encoding

Parameters
int$bufferSizebuffer size to use for reading
Returns
string
Exceptions
HTTP_Request2_MessageException

Definition at line 1093 of file Socket.php.

HTTP_Request2_Adapter_Socket::readResponse ( )
protected

Reads the remote server's response

Returns
HTTP_Request2_Response
Exceptions
HTTP_Request2_Exception

Definition at line 1002 of file Socket.php.

HTTP_Request2_Adapter_Socket::sendRequest ( HTTP_Request2  $request)

Sends request to the remote server and returns its response

Parameters
HTTP_Request2$requestHTTP request message
Returns
HTTP_Request2_Response
Exceptions
HTTP_Request2_Exception

Definition at line 123 of file Socket.php.

HTTP_Request2_Adapter_Socket::shouldUseProxyDigestAuth ( HTTP_Request2_Response  $response)
protected

Checks whether another request should be performed with proxy digest auth

Several conditions should be satisfied for it to return true:

  • response status should be 407
  • proxy auth credentials should be set in the request object
  • response should contain Proxy-Authenticate header with digest challenge
  • there is either no challenge stored for this proxy or new challenge contains stale=true parameter (in other case we probably just failed due to invalid username / password)

The method stores challenge values in $challenges static property

Parameters
HTTP_Request2_Response$responseresponse to check
Returns
boolean whether another request should be performed
Exceptions
HTTP_Request2_Exceptionin case of unsupported challenge parameters

Definition at line 548 of file Socket.php.

HTTP_Request2_Adapter_Socket::shouldUseServerDigestAuth ( HTTP_Request2_Response  $response)
protected

Checks whether another request should be performed with server digest auth

Several conditions should be satisfied for it to return true:

  • response status should be 401
  • auth credentials should be set in the request object
  • response should contain WWW-Authenticate header with digest challenge
  • there is either no challenge stored for this URL or new challenge contains stale=true parameter (in other case we probably just failed due to invalid username / password)

The method stores challenge values in $challenges static property

Parameters
HTTP_Request2_Response$responseresponse to check
Returns
boolean whether another request should be performed
Exceptions
HTTP_Request2_Exceptionin case of unsupported challenge parameters

Definition at line 483 of file Socket.php.

HTTP_Request2_Adapter_Socket::updateChallenge ( $challenge,
  $headerValue 
)
protected

Parses [Proxy-]Authentication-Info header value and updates challenge

Parameters
array&$challengechallenge to update
string$headerValuevalue of [Proxy-]Authentication-Info header
Todo:
validate server rspauth response

Definition at line 651 of file Socket.php.

HTTP_Request2_Adapter_Socket::updateExpectHeader ( $headers)
protected

Adds or removes 'Expect: 100-continue' header from request headers

Also sets the $expect100Continue property. Parsing of existing header is somewhat needed due to its complex structure and due to the requirement in section 8.2.3 of RFC 2616:

A client MUST NOT send an Expect request-header field (section 14.20) with the "100-continue" expectation if it does not intend to send a request body.

Parameters
array&$headersArray of headers prepared for the request
Exceptions
HTTP_Request2_LogicExceptionhttp://tools.ietf.org/html/rfc2616#section-8.2.3

Definition at line 898 of file Socket.php.

HTTP_Request2_Adapter_Socket::writeBody ( )
protected

Sends the request body

Exceptions
HTTP_Request2_MessageException

Definition at line 959 of file Socket.php.

Member Data Documentation

HTTP_Request2_Adapter_Socket::$challenges = array()
staticprotected

Definition at line 71 of file Socket.php.

HTTP_Request2_Adapter_Socket::$chunkLength = 0
protected

Definition at line 97 of file Socket.php.

HTTP_Request2_Adapter_Socket::$expect100Continue = false
protected

Definition at line 113 of file Socket.php.

HTTP_Request2_Adapter_Socket::$proxyChallenge
protected

Definition at line 90 of file Socket.php.

HTTP_Request2_Adapter_Socket::$redirectCountdown = null
protected

Definition at line 107 of file Socket.php.

HTTP_Request2_Adapter_Socket::$serverChallenge
protected

Definition at line 84 of file Socket.php.

HTTP_Request2_Adapter_Socket::$socket
protected

Definition at line 78 of file Socket.php.

HTTP_Request2_Adapter_Socket::$sockets = array()
staticprotected

Definition at line 57 of file Socket.php.

const HTTP_Request2_Adapter_Socket::REGEXP_QUOTED_STRING = '"(?>[^"\\\\]+|\\\\.)*"'

Regular expression for 'quoted-string' rule from RFC 2616

Definition at line 50 of file Socket.php.

const HTTP_Request2_Adapter_Socket::REGEXP_TOKEN = '[^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+'

Regular expression for 'token' rule from RFC 2616

Definition at line 45 of file Socket.php.


The documentation for this class was generated from the following file: