TYPO3  7.6
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

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.

References HTTP_Request2\AUTH_BASIC, HTTP_Request2\AUTH_DIGEST, and createDigestResponse().

Referenced by prepareHeaders().

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.

References HTTP_Request2\AUTH_BASIC, HTTP_Request2\AUTH_DIGEST, createDigestResponse(), and HTTP_Request2\METHOD_CONNECT.

Referenced by prepareHeaders().

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.

References HTTP_Request2_Response\getHeader(), HTTP_Request2_Response\getStatus(), HTTP_Request2_Response\getVersion(), HTTP_Request2\METHOD_CONNECT, and HTTP_Request2\METHOD_HEAD.

Referenced by sendRequest().

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.

References $socket, elseif, establishTunnel(), HTTP_Request2\METHOD_CONNECT, HTTP_Request2_Exception\MISCONFIGURATION, HTTP_Request2_Exception\MISSING_VALUE, and HTTP_Request2_SocketWrapper\setDeadline().

Referenced by sendRequest().

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.

References $url.

Referenced by addAuthorizationHeader(), and addProxyAuthorizationHeader().

disconnect ( )
protected

Disconnects from the remote server

Definition at line 395 of file Socket.php.

Referenced by sendRequest().

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.

References $response, and HTTP_Request2\METHOD_CONNECT.

Referenced by connect().

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.

References HTTP_Request2_Adapter\$request, HTTP_Request2\getConfig(), HTTP_Request2_Response\getHeader(), HTTP_Request2_Response\getStatus(), HTTP_Request2\getUrl(), HTTP_Request2\METHOD_GET, HTTP_Request2_Exception\NON_HTTP_REDIRECT, Net_URL2\OPTION_USE_BRACKETS, sendRequest(), and HTTP_Request2_Exception\TOO_MANY_REDIRECTS.

Referenced by sendRequest().

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.

Referenced by shouldUseProxyDigestAuth(), and shouldUseServerDigestAuth().

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.

References $url, addAuthorizationHeader(), addProxyAuthorizationHeader(), HTTP_Request2_Adapter\calculateRequestLength(), HTTP_Request2\METHOD_CONNECT, and updateExpectHeader().

Referenced by sendRequest().

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.

References HTTP_Request2_Exception\DECODE_ERROR.

Referenced by readResponse().

readResponse ( )
protected
sendRequest ( HTTP_Request2  $request)
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.

References HTTP_Request2_Response\getHeader(), HTTP_Request2_Response\getStatus(), and parseDigestChallenge().

Referenced by sendRequest().

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.

References $url, HTTP_Request2_Response\getHeader(), HTTP_Request2_Response\getStatus(), and parseDigestChallenge().

Referenced by sendRequest().

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.

Referenced by sendRequest().

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.

References elseif, and HTTP_Request2_Exception\INVALID_ARGUMENT.

Referenced by prepareHeaders().

writeBody ( )
protected

Sends the request body

Exceptions
HTTP_Request2_MessageException

Definition at line 959 of file Socket.php.

References elseif.

Referenced by sendRequest().

Member Data Documentation

$challenges = array()
staticprotected

Definition at line 71 of file Socket.php.

$chunkLength = 0
protected

Definition at line 97 of file Socket.php.

$expect100Continue = false
protected

Definition at line 113 of file Socket.php.

Referenced by readResponse().

$proxyChallenge
protected

Definition at line 90 of file Socket.php.

$redirectCountdown = null
protected

Definition at line 107 of file Socket.php.

$serverChallenge
protected

Definition at line 84 of file Socket.php.

$socket
protected

Definition at line 78 of file Socket.php.

Referenced by connect().

$sockets = array()
staticprotected

Definition at line 57 of file Socket.php.

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

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

Definition at line 50 of file Socket.php.

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

Regular expression for 'token' rule from RFC 2616

Definition at line 45 of file Socket.php.