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

Class: HTTP_Request2_Response

Source Location: /HTTP_Request2-2.2.1/HTTP/Request2/Response.php

Class Overview


Class representing a HTTP response


Author(s):

Version:

  • Release: 2.2.1

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 54]
Class representing a HTTP response

The class is designed to be used in "streaming" scenario, building the response as it is being received:

  1.  $statusLine = read_status_line();
  2.  $response = new HTTP_Request2_Response($statusLine);
  3.  do {
  4.      $headerLine = read_header_line();
  5.      $response->parseHeaderLine($headerLine);
  6.  while ($headerLine != '');
  7.  
  8.  while ($chunk = read_body()) {
  9.      $response->appendBody($chunk);
  10.  }
  11.  
  12.  var_dump($response->getHeader()$response->getCookies()$response->getBody());



[ Top ]


Class Variables

$body =  ''

[line 107]

Response body
  • Access: protected

Type:   string


[ Top ]

$bodyEncoded =

[line 117]

Whether the body is still encoded by Content-Encoding

cURL provides the decoded body to the callback; if we are reading from socket the body is still gzipped / deflated

  • Access: protected

Type:   bool


[ Top ]

$code =

[line 67]

Status code

Type:   integer


[ Top ]

$cookies = array()

[line 92]

Cookies set in the response
  • Access: protected

Type:   array


[ Top ]

$effectiveUrl =

[line 80]

Effective URL (may be different from original request URL in case of redirects)
  • Access: protected

Type:   string


[ Top ]

$headers = array()

[line 86]

Associative array of response headers
  • Access: protected

Type:   array


[ Top ]

$lastHeader =  null

[line 101]

Name of last header processed by parseHederLine()

Used to handle the headers that span multiple lines

  • Access: protected

Type:   string


[ Top ]

$phrases = array(

        // 1xx: Informational - Request received, continuing process
        100 => 'Continue',
        101 => 'Switching Protocols',

        // 2xx: Success - The action was successfully received, understood and
        // accepted
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',

        // 3xx: Redirection - Further action must be taken in order to complete
        // the request
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',  // 1.1
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        307 => 'Temporary Redirect',

        // 4xx: Client Error - The request contains bad syntax or cannot be
        // fulfilled
        400 => 'Bad Request',
        401 => 'Unauthorized',
        402 => 'Payment Required',
        403 => 'Forbidden',
        404 => 'Not Found',
        405 => 'Method Not Allowed',
        406 => 'Not Acceptable',
        407 => 'Proxy Authentication Required',
        408 => 'Request Timeout',
        409 => 'Conflict',
        410 => 'Gone',
        411 => 'Length Required',
        412 => 'Precondition Failed',
        413 => 'Request Entity Too Large',
        414 => 'Request-URI Too Long',
        415 => 'Unsupported Media Type',
        416 => 'Requested Range Not Satisfiable',
        417 => 'Expectation Failed',

        // 5xx: Server Error - The server failed to fulfill an apparently
        // valid request
        500 => 'Internal Server Error',
        501 => 'Not Implemented',
        502 => 'Bad Gateway',
        503 => 'Service Unavailable',
        504 => 'Gateway Timeout',
        505 => 'HTTP Version Not Supported',
        509 => 'Bandwidth Limit Exceeded',

    )

[line 125]

Associative array of HTTP status code / reason phrase.

Type:   array


[ Top ]

$reasonPhrase =

[line 74]

Reason phrase

Type:   string


[ Top ]

$version =

[line 60]

HTTP protocol version (e.g. 1.0, 1.1)
  • Access: protected

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 212]

HTTP_Request2_Response __construct( string $statusLine, [bool $bodyEncoded = true], [string $effectiveUrl = null])

Constructor, parses the response status line
  • Throws: HTTP_Request2_MessageException if status line is invalid according to spec
  • Access: public

Parameters:

string   $statusLine   —  Response status line (e.g. "HTTP/1.1 200 OK")
bool   $bodyEncoded   —  Whether body is still encoded by Content-Encoding
string   $effectiveUrl   —  Effective URL of the response

[ Top ]

appendBody   [line 339]

void appendBody( string $bodyChunk)

Appends a string to the response body
  • Access: public

Parameters:

string   $bodyChunk   —  part of response body

[ Top ]

decodeDeflate   [line 615]

string decodeDeflate( string $data)

Decodes the message-body encoded by deflate
  • Return: decoded data
  • Throws: HTTP_Request2_LogicException
  • Access: public

Parameters:

string   $data   —  deflate-encoded data

[ Top ]

decodeGzip   [line 481]

string decodeGzip( string $data)

Decodes the message-body encoded by gzip

The real decoding work is done by gzinflate() built-in function, this method only parses the header and checks data for compliance with RFC 1952


Parameters:

string   $data   —  gzip-encoded data

[ Top ]

getBody   [line 423]

string getBody( )

Returns the body of the response
  • Throws: HTTP_Request2_Exception if body cannot be decoded
  • Access: public

[ Top ]

getCookies   [line 412]

array getCookies( )

Returns cookies set in response
  • Access: public

[ Top ]

getDefaultReasonPhrase   [line 194]

string|array|null getDefaultReasonPhrase( [int $code = null])

Returns the default reason phrase for the given code or all reason phrases
  • Return: Default reason phrase for $code if $code is given (null if no phrase is available), array of all reason phrases if $code is null
  • Link: http://pear.php.net/bugs/18716
  • Access: public

Parameters:

int   $code   —  Response code

[ Top ]

getEffectiveUrl   [line 352]

string getEffectiveUrl( )

Returns the effective URL of the response

This may be different from the request URL if redirects were followed.


[ Top ]

getHeader   [line 397]

string|array getHeader( [string $headerName = null])

Returns either the named header or all response headers
  • Return: Value of $headerName header (null if header is not present), array of all response headers if $headerName is null
  • Access: public

Parameters:

string   $headerName   —  Name of header to return

[ Top ]

getReasonPhrase   [line 372]

string getReasonPhrase( )

Returns the reason phrase
  • Access: public

[ Top ]

getStatus   [line 362]

integer getStatus( )

Returns the status code
  • Access: public

[ Top ]

getVersion   [line 462]

string getVersion( )

Get the HTTP version of the response
  • Access: public

[ Top ]

isRedirect   [line 382]

bool isRedirect( )

Whether response is a redirect that can be automatically handled by HTTP_Request2
  • Access: public

[ Top ]

parseCookie   [line 290]

void parseCookie( string $cookieString)

Parses a Set-Cookie header to fill $cookies array

Parameters:

string   $cookieString   —  value of Set-Cookie header

[ Top ]

parseHeaderLine   [line 237]

void parseHeaderLine( string $headerLine)

Parses the line from HTTP response filling $headers array

The method should be called after reading the line from socket or receiving it into cURL callback. Passing an empty string here indicates the end of response headers and triggers additional processing, so be sure to pass an empty string in the end.

  • Access: public

Parameters:

string   $headerLine   —  Line from HTTP response

[ Top ]


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