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

Class: Microsoft_Http_Response

Source Location: /Http/Response.php

Class Overview


Microsoft_Http_Response represents an HTTP 1.0 / 1.1 response message. It includes easy access to all the response's different elemts, as well as some convenience methods for parsing and validating HTTP responses.


Author(s):

Copyright:

  • Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)

Variables

Methods


Child classes:

Microsoft_Http_Response_Stream
Microsoft_Http_Response represents an HTTP 1.0 / 1.1 response message. It includes easy access to all the response's different elemts, as well as some convenience methods for parsing and validating HTTP responses.

Class Details

[line 34]
Microsoft_Http_Response represents an HTTP 1.0 / 1.1 response message. It includes easy access to all the response's different elemts, as well as some convenience methods for parsing and validating HTTP responses.



Tags:

copyright:  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
license:  New BSD License


[ Top ]


Class Variables

static $messages = array(
        // Informational 1xx
        100 => 'Continue',
        101 => 'Switching Protocols',

        // Success 2xx
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',

        // Redirection 3xx
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',  // 1.1
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        // 306 is deprecated but reserved
        307 => 'Temporary Redirect',

        // Client Error 4xx
        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',

        // Server Error 5xx
        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 42]

List of all known HTTP response codes - used by responseCodeAsText() to translate numeric codes to messages.



Tags:

access:  protected

Type:   array


[ Top ]

$body =

[line 130]

The HTTP response body



Tags:

access:  protected

Type:   string


[ Top ]

$code =

[line 108]

The HTTP response code



Tags:

access:  protected

Type:   int


[ Top ]

$headers = array()

[line 123]

The HTTP response headers array



Tags:

access:  protected

Type:   array


[ Top ]

$message =

[line 116]

The HTTP response code as string (e.g. 'Not Found' for 404 or 'Internal Server Error' for 500)



Tags:

access:  protected

Type:   string


[ Top ]

$version =

[line 101]

The HTTP version (1.0, 1.1)



Tags:

access:  protected

Type:   string


[ Top ]



Class Methods


static method decodeChunkedBody [line 560]

static string decodeChunkedBody( string $body)

Decode a "chunked" transfer-encoded body and return the decoded text



Tags:

access:  public


Parameters:

string   $body  

[ Top ]

static method decodeDeflate [line 620]

static string decodeDeflate( string $body)

Decode a zlib deflated message (when Content-encoding = deflate)

Currently requires PHP with zlib support




Tags:

access:  public


Parameters:

string   $body  

[ Top ]

static method decodeGzip [line 600]

static string decodeGzip( string $body)

Decode a gzip encoded message (when Content-encoding = gzip)

Currently requires PHP with zlib support




Tags:

access:  public


Parameters:

string   $body  

[ Top ]

static method extractBody [line 545]

static string extractBody( string $response_str)

Extract the body from a response string



Tags:

access:  public


Parameters:

string   $response_str  

[ Top ]

static method extractCode [line 442]

static int extractCode( string $response_str)

Extract the response code from a response string



Tags:

access:  public


Parameters:

string   $response_str  

[ Top ]

static method extractHeaders [line 493]

static array extractHeaders( string $response_str)

Extract the headers from a response string



Tags:

access:  public


Parameters:

string   $response_str  

[ Top ]

static method extractMessage [line 459]

static string extractMessage( string $response_str)

Extract the HTTP message from a response



Tags:

access:  public


Parameters:

string   $response_str  

[ Top ]

static method extractVersion [line 476]

static string extractVersion( string $response_str)

Extract the HTTP version from a response



Tags:

access:  public


Parameters:

string   $response_str  

[ Top ]

static method fromString [line 654]

static Microsoft_Http_Response fromString( string $response_str)

Create a new Microsoft_Http_Response object from a string



Tags:

access:  public


Parameters:

string   $response_str  

[ Top ]

static method responseCodeAsText [line 422]

static string responseCodeAsText( [int $code = null], [boolean $http11 = true])

A convenience function that returns a text representation of HTTP response codes. Returns 'Unknown' for unknown codes.

Returns array of all codes, if $code is not specified.

Conforms to HTTP/1.1 as defined in RFC 2616 (except for 'Unknown') See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 for reference




Tags:

access:  public


Parameters:

int   $code   HTTP response code
boolean   $http11   Use HTTP version 1.1

[ Top ]

constructor __construct [line 151]

Microsoft_Http_Response __construct( int $code, array $headers, [string $body = null], [string $version = '1.1'], [string $message = null])

HTTP response constructor

In most cases, you would use Microsoft_Http_Response::fromString to parse an HTTP response string and create a new Microsoft_Http_Response object.

NOTE: The constructor no longer accepts nulls or empty values for the code and headers and will throw an exception if the passed values do not form a valid HTTP responses.

If no message is passed, the message will be guessed according to the response code.




Tags:

throws:  Microsoft_Http_Exception
access:  public


Overridden in child classes as:

Microsoft_Http_Response_Stream::__construct()
HTTP response constructor

Parameters:

int   $code   Response code (200, 404, ...)
array   $headers   Headers array
string   $body   Response body
string   $version   HTTP version
string   $message   Response code as text

[ Top ]

method asString [line 395]

string asString( [string $br = "\n"])

Get the entire response as string



Tags:

access:  public


Parameters:

string   $br   Line breaks (eg. "\n", "\r\n", "
")

[ Top ]

method getBody [line 251]

string getBody( )

Get the response body as string

This method returns the body of the HTTP response (the content), as it should be in it's readable version - that is, after decoding it (if it was decoded), deflating it (if it was gzip compressed), etc.

If you want to get the raw body (as transfered on wire) use $this->getRawBody() instead.




Tags:

access:  public


Overridden in child classes as:

Microsoft_Http_Response_Stream::getBody()
Get the response body as string

[ Top ]

method getHeader [line 350]

string|array|null getHeader( string$header $header)

Get a specific header as string, or null if it is not set



Tags:

access:  public


Parameters:

string$header   $header  

[ Top ]

method getHeaders [line 339]

array getHeaders( )

Get the response headers



Tags:

access:  public


[ Top ]

method getHeadersAsString [line 365]

string getHeadersAsString( [boolean $status_line = true], [string $br = "\n"])

Get all headers as string



Tags:

access:  public


Parameters:

boolean   $status_line   Whether to return the first status line (IE "HTTP 200 OK")
string   $br   Line breaks (eg. "\n", "\r\n", "
")

[ Top ]

method getMessage [line 329]

string getMessage( )

Return a message describing the HTTP response code (Eg. "OK", "Not Found", "Moved Permanently")



Tags:

access:  public


[ Top ]

method getRawBody [line 298]

string getRawBody( )

Get the raw response body (as transfered "on wire") as string

If the body is encoded (with Transfer-Encoding, not content-encoding - IE "chunked" body), gzip compressed, etc. it will not be decoded.




Tags:

access:  public


Overridden in child classes as:

Microsoft_Http_Response_Stream::getRawBody()
Get the raw response body (as transfered "on wire") as string

[ Top ]

method getStatus [line 318]

int getStatus( )

Get the HTTP response status code



Tags:

access:  public


[ Top ]

method getVersion [line 308]

string getVersion( )

Get the HTTP version of the response



Tags:

access:  public


[ Top ]

method isError [line 199]

boolean isError( )

Check whether the response is an error



Tags:

access:  public


[ Top ]

method isRedirect [line 229]

boolean isRedirect( )

Check whether the response is a redirection



Tags:

access:  public


[ Top ]

method isSuccessful [line 214]

boolean isSuccessful( )

Check whether the response in successful



Tags:

access:  public


[ Top ]

method __toString [line 405]

string __toString( )

Implements magic __toString()



Tags:

access:  public


[ Top ]


Documentation generated on Wed, 18 May 2011 12:06:46 +0200 by phpDocumentor 1.4.3