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

Class: HTTP_Request2_Response

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

Class Overview


Class representing a HTTP response


Author(s):

Version:

  • Release: 2.1.0

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 77]
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 130]

Response body
  • Access: protected

Type:   string


[ Top ]

$bodyEncoded =

[line 140]

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

Status code

Type:   integer


[ Top ]

$cookies = array()

[line 115]

Cookies set in the response
  • Access: protected

Type:   array


[ Top ]

$effectiveUrl =

[line 103]

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

Type:   string


[ Top ]

$headers = array()

[line 109]

Associative array of response headers
  • Access: protected

Type:   array


[ Top ]

$lastHeader =  null

[line 124]

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

Associative array of HTTP status code / reason phrase.

Type:   array


[ Top ]

$reasonPhrase =

[line 97]

Reason phrase

Type:   string


[ Top ]

$version =

[line 83]

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

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 235]

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

void appendBody( string $bodyChunk)

Appends a string to the response body
  • Access: public

Parameters:

string   $bodyChunk   —  part of response body

[ Top ]

decodeDeflate   [line 638]

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

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

string getBody( )

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

[ Top ]

getCookies   [line 435]

array getCookies( )

Returns cookies set in response
  • Access: public

[ Top ]

getDefaultReasonPhrase   [line 217]

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

Returns the default reason phrase for the given code or all reason phrases

Parameters:

int   $code   —  Response code

[ Top ]

getEffectiveUrl   [line 375]

string getEffectiveUrl( )

Returns the effective URL of the response

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


[ Top ]

getHeader   [line 420]

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

string getReasonPhrase( )

Returns the reason phrase
  • Access: public

[ Top ]

getStatus   [line 385]

integer getStatus( )

Returns the status code
  • Access: public

[ Top ]

getVersion   [line 485]

string getVersion( )

Get the HTTP version of the response
  • Access: public

[ Top ]

isRedirect   [line 405]

bool isRedirect( )

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

[ Top ]

parseCookie   [line 313]

void parseCookie( string $cookieString)

Parses a Set-Cookie header to fill $cookies array

Parameters:

string   $cookieString   —  value of Set-Cookie header

[ Top ]

parseHeaderLine   [line 260]

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:48:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.