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

Class: HTTP_Request2_Adapter_Socket

Source Location: /HTTP_Request2-0.3.0/Request2/Adapter/Socket.php

Class Overview

HTTP_Request2_Adapter
   |
   --HTTP_Request2_Adapter_Socket

Socket-based adapter for HTTP_Request2


Author(s):

Version:

  • Release: 0.3.0

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 60]
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 91]

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 123]

Remaining length of the current chunk, when reading chunked response

Type:   integer


[ Top ]

$proxyChallenge =

[line 110]

Challenge used for proxy digest authentication
  • Access: protected

Type:   array


[ Top ]

$serverChallenge =

[line 104]

Challenge used for server digest authentication
  • Access: protected

Type:   array


[ Top ]

$socket =

[line 98]

Connected socket

Type:   resource


[ Top ]

$sockets = array()

[line 77]

Connected sockets, needed for Keep-Alive support

Type:   array


[ Top ]

$timeout =  null

[line 116]

Global timeout, exception will be raised if request continues past this time
  • Access: protected

Type:   integer


[ Top ]



Method Detail

addAuthorizationHeader   [line 637]

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

Adds 'Authorization' header (if needed) to request headers array
  • Throws: HTTP_Request2_Exception
  • 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 680]

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

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

Parameters:

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

[ Top ]

canKeepAlive   [line 352]

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 193]

bool connect( )

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

[ Top ]

createDigestResponse   [line 594]

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 372]

void disconnect( )

Disconnects from the remote server
  • Access: protected

[ Top ]

establishTunnel   [line 309]

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 ]

fread   [line 913]

Data fread( int $length)

Wrapper around fread(), handles global request timeout
  • Return: read from socket
  • Throws: HTTP_Request2_Exception In case of timeout
  • Access: protected

Parameters:

int   $length   —  Reads up to this number of bytes

[ Top ]

parseDigestChallenge   [line 513]

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 here are defined as quoted-string 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_Exception in case of unsupported challenge parameters
  • Access: protected

Parameters:

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

[ Top ]

prepareHeaders   [line 725]

string prepareHeaders( )

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

[ Top ]

readChunked   [line 936]

string readChunked( int $bufferSize)

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

Parameters:

int   $bufferSize   —  buffer size to use for reading

[ Top ]

readLine   [line 884]

Available readLine( int $bufferSize)

Reads until either the end of the socket or a newline, whichever comes first

Strips the trailing newline from the returned data, handles global request timeout. Method idea borrowed from Net_Socket PEAR package.

  • Return: data up to the newline (not including newline)
  • Throws: HTTP_Request2_Exception In case of timeout
  • Access: protected

Parameters:

int   $bufferSize   —  buffer size to use for reading

[ Top ]

readResponse   [line 811]

HTTP_Request2_Response readResponse( )

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

[ Top ]

sendRequest   [line 132]

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   — 

[ Top ]

shouldUseProxyDigestAuth   [line 462]

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 398]

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 563]

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 ]

writeBody   [line 778]

void writeBody( )

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

[ Top ]


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