HTTP_Request2
[ class tree: HTTP_Request2 ] [ index: HTTP_Request2 ] [ all elements ]

Class: HTTP_Request2_Adapter_Socket

Source Location: /HTTP_Request2-2.2.1/HTTP/Request2/Adapter/Socket.php

Class Overview

HTTP_Request2_Adapter
   |
   --HTTP_Request2_Adapter_Socket

Socket-based adapter for HTTP_Request2


Author(s):

Version:

  • Release: 2.2.1

Variables

Methods


Inherited Variables

Inherited Methods

Class: HTTP_Request2_Adapter

HTTP_Request2_Adapter::calculateRequestLength()
Calculates length of the request body, adds proper headers
HTTP_Request2_Adapter::sendRequest()
Sends request to the remote server and returns its response

Class Details

[line 40]
Socket-based adapter for HTTP_Request2

This adapter uses only PHP sockets and will work on almost any PHP environment. Code is based on original HTTP_Request PEAR package.



[ Top ]


Class Variables

$challenges = array()

[line 71]

Data for digest authentication scheme

The keys for the array are URL prefixes.

The values are associative arrays with data (realm, nonce, nonce-count, opaque...) needed for digest authentication. Stored here to prevent making duplicate requests to digest-protected resources after we have already received the challenge.

  • Access: protected

Type:   array


[ Top ]

$chunkLength =  0

[line 97]

Remaining length of the current chunk, when reading chunked response

Type:   integer


[ Top ]

$expect100Continue =  false

[line 113]

Whether to wait for "100 Continue" response before sending request body
  • Access: protected

Type:   bool


[ Top ]

$proxyChallenge =

[line 90]

Challenge used for proxy digest authentication
  • Access: protected

Type:   array


[ Top ]

$redirectCountdown =  null

[line 107]

Remaining amount of redirections to follow

Starts at 'max_redirects' configuration parameter and is reduced on each subsequent redirect. An Exception will be thrown once it reaches zero.

  • Access: protected

Type:   integer


[ Top ]

$serverChallenge =

[line 84]

Challenge used for server digest authentication
  • Access: protected

Type:   array


[ Top ]

$socket =

[line 78]

Connected socket



[ Top ]

$sockets = array()

[line 57]

Connected sockets, needed for Keep-Alive support

Type:   array


[ Top ]



Method Detail

addAuthorizationHeader   [line 729]

void addAuthorizationHeader( array &$headers, string $requestHost, string $requestUrl)

Adds 'Authorization' header (if needed) to request headers array
  • Throws: HTTP_Request2_NotImplementedException
  • Access: protected

Parameters:

array   &$headers   —  request headers
string   $requestHost   —  request host (needed for digest authentication)
string   $requestUrl   —  request URL (needed for digest authentication)

[ Top ]

addProxyAuthorizationHeader   [line 774]

void addProxyAuthorizationHeader( array &$headers, string $requestUrl)

Adds 'Proxy-Authorization' header (if needed) to request headers array
  • Throws: HTTP_Request2_NotImplementedException
  • Access: protected

Parameters:

array   &$headers   —  request headers
string   $requestUrl   —  request URL (needed for digest authentication)

[ Top ]

canKeepAlive   [line 372]

boolean canKeepAlive( boolean $requestKeepAlive, HTTP_Request2_Response $response)

Checks whether current connection may be reused or should be closed
  • Access: protected

Parameters:

boolean   $requestKeepAlive   —  whether connection could be persistent in the first place
HTTP_Request2_Response   $response   —  response object to check

[ Top ]

connect   [line 195]

bool connect( )

Connects to the remote server
  • Return: whether the connection can be persistent
  • Throws: HTTP_Request2_Exception
  • Access: protected

[ Top ]

createDigestResponse   [line 683]

string createDigestResponse( string $user, string $password, string $url, array &$challenge)

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

Parameters:

string   $user   —  user name
string   $password   —  password
string   $url   —  request URL
array   &$challenge   —  digest challenge parameters

[ Top ]

disconnect   [line 395]

void disconnect( )

Disconnects from the remote server
  • Access: protected

[ Top ]

establishTunnel   [line 344]

void establishTunnel( )

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.


[ Top ]

handleRedirect   [line 416]

HTTP_Request2_Response handleRedirect( HTTP_Request2 $request, HTTP_Request2_Response $response)

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.

  • Return: Response from a new location
  • Throws: HTTP_Request2_Exception
  • Access: protected

Parameters:

HTTP_Request2   $request   —  Original request
HTTP_Request2_Response   $response   —  Response containing redirect

[ Top ]

parseDigestChallenge   [line 600]

mixed parseDigestChallenge( string $headerValue)

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

  • Return: associative array with challenge parameters, false if no challenge is present in header value
  • Throws: HTTP_Request2_NotImplementedException in case of unsupported challenge parameters
  • Access: protected

Parameters:

string   $headerValue   —  value of WWW-Authenticate or Proxy-Authenticate header

[ Top ]

prepareHeaders   [line 820]

string prepareHeaders( )

Creates the string with the Request-Line and request headers
  • Throws: HTTP_Request2_Exception
  • Access: protected

[ Top ]

readChunked   [line 1093]

string readChunked( int $bufferSize)

Reads a part of response body encoded with chunked Transfer-Encoding
  • Throws: HTTP_Request2_MessageException
  • Access: protected

Parameters:

int   $bufferSize   —  buffer size to use for reading

[ Top ]

readResponse   [line 1002]

HTTP_Request2_Response readResponse( )

Reads the remote server's response
  • Throws: HTTP_Request2_Exception
  • Access: protected

[ Top ]

sendRequest   [line 123]

HTTP_Request2_Response sendRequest( HTTP_Request2 $request)

Sends request to the remote server and returns its response
  • Throws: HTTP_Request2_Exception
  • Access: public

Overrides HTTP_Request2_Adapter::sendRequest() (Sends request to the remote server and returns its response)

Parameters:

HTTP_Request2   $request   —  HTTP request message

[ Top ]

shouldUseProxyDigestAuth   [line 548]

boolean shouldUseProxyDigestAuth( HTTP_Request2_Response $response)

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

  • Return: whether another request should be performed
  • Throws: HTTP_Request2_Exception in case of unsupported challenge parameters
  • Access: protected

Parameters:

HTTP_Request2_Response   $response   —  response to check

[ Top ]

shouldUseServerDigestAuth   [line 483]

boolean shouldUseServerDigestAuth( HTTP_Request2_Response $response)

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

  • Return: whether another request should be performed
  • Throws: HTTP_Request2_Exception in case of unsupported challenge parameters
  • Access: protected

Parameters:

HTTP_Request2_Response   $response   —  response to check

[ Top ]

updateChallenge   [line 651]

void updateChallenge( array &$challenge, string $headerValue)

Parses [Proxy-]Authentication-Info header value and updates challenge
  • Todo: validate server rspauth response
  • Access: protected

Parameters:

array   &$challenge   —  challenge to update
string   $headerValue   —  value of [Proxy-]Authentication-Info header

[ Top ]

updateExpectHeader   [line 898]

void updateExpectHeader( array &$headers)

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   &$headers   —  Array of headers prepared for the request

[ Top ]

writeBody   [line 959]

void writeBody( )

Sends the request body
  • Throws: HTTP_Request2_MessageException
  • Access: protected

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:56:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.