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

Class: HTTP_Request2_Response

Source Location: /HTTP_Request2-0.1.0/Request2/Response.php

Class Overview


Class representing a HTTP response


Author(s):

Version:

  • Release: 0.1.0

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 76]
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 123]

Response body
  • Access: protected

Type:   string


[ Top ]

$bodyEncoded =

[line 133]

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

Status code

Type:   integer


[ Top ]

$cookies = array()

[line 108]

Cookies set in the response
  • Access: protected

Type:   array


[ Top ]

$headers = array()

[line 102]

Associative array of response headers
  • Access: protected

Type:   array


[ Top ]

$lastHeader =  null

[line 117]

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

Associative array of HTTP status code / reason phrase.

Type:   array


[ Top ]

$reasonPhrase =

[line 96]

Reason phrase

Type:   string


[ Top ]

$version =

[line 82]

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

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 207]

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

Constructor, parses the response status line
  • Throws: HTTP_Request2_Exception 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

[ Top ]

appendBody   [line 332]

void appendBody( string $bodyChunk)

Appends a string to the response body
  • Access: public

Parameters:

string   $bodyChunk   — 

[ Top ]

decodeDeflate   [line 515]

string decodeDeflate( string $data)

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

Parameters:

string   $data   —  deflate-encoded data

[ Top ]

decodeGzip   [line 424]

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

string getBody( )

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

[ Top ]

getCookies   [line 378]

array getCookies( )

Returns cookies set in response
  • Access: public

[ Top ]

getHeader   [line 363]

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

string getReasonPhrase( )

Returns the reason phrase
  • Access: public

[ Top ]

getStatus   [line 341]

integer getStatus( )

Returns the status code
  • Access: public

[ Top ]

getVersion   [line 407]

string getVersion( )

Get the HTTP version of the response
  • Access: public

[ Top ]

parseCookie   [line 284]

void parseCookie( string $cookieString)

Parses a Set-Cookie header to fill $cookies array

Parameters:

string   $cookieString   —  value of Set-Cookie header

[ Top ]

parseHeaderLine   [line 232]

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