Previous Next

Zend\Http\Headers And The Various Header Classes


The Zend\Http\Headers class is a container for HTTP headers. It is typically accessed as part of a Zend\Http\Request or Zend\Http\Response header() call. The Headers container will lazily load actual Header objects as to reduce the overhead of header specific parsing.

The Zend\Http\Header\* classes are the domain specific implementations for the various types of Headers that one might encounter during the typical HTTP request. If a header of unknown type is encountered, it will be implemented as a Zend\Http\Header\GenericHeader instance. See the below table for a list of the various HTTP headers and the API that is specific to each header type.

Quick Start

The quickest way to get started interacting with header objects is by getting an already populated Headers container from a request or response object.

Configuration Options

None currently available.

Available Methods

Headers::fromString ( string $string )

Populates headers from string representation

Parses a string for headers, and aggregates them, in order, in the current instance, primarily as strings until they are needed (they will be lazy loaded).

Returns Zend\Http\Headers

setPluginClassLoader ( Zend\Loader\PluginClassLocator $pluginClassLoader )

Set an alternate implementation for the plugin class loader

Returns Zend\Http\Headers

getPluginClassLoader )

Return an instance of a Zend\Loader\PluginClassLocator, lazyload and inject map if necessary.

Returns Zend\Loader\PluginClassLocator

addHeaders ( array|Traversable $headers )

Add many headers at once

Expects an array (or Traversable object) of type/value pairs.

Returns Zend\Http\Headers

addHeaderLine ( string $headerFieldNameOrLine, string $fieldValue )

Add a raw header line, either in name => value, or as a single string 'name: value'

This method allows for lazy-loading in that the parsing and instantiation of Header object will be delayed until they are retrieved by either get() or current().

Returns Zend\Http\Headers

addHeader ( Zend\Http\Header\HeaderDescription $header )

Add a Header to this container, for raw values see addHeaderLine() and addHeaders().

Returns Zend\Http\Headers

removeHeader ( Zend\Http\Header\HeaderDescription $header )

Remove a Header from the container

Returns bool

clearHeaders )

Clear all headers

Removes all headers from queue

Returns Zend\Http\Headers

get ( string $name )

Get all headers of a certain name/type

Returns false|Zend\Http\Header\HeaderDescription|ArrayIterator

has ( string $name )

Test for existence of a type of header

Returns bool

next )

Advance the pointer for this object as an interator

Returns void

key )

Return the current key for this object as an interator

Returns mixed

valid )

Is this iterator still valid?

Returns bool

rewind )

Reset the internal pointer for this object as an iterator

Returns void

current )

Return the current value for this iterator, lazy loading it if need be

Returns Zend\Http\Header\HeaderDescription

count )

Return the number of headers in this container. If all headers have not been parsed, actual count could increase if MultipleHeader objects exist in the Request/Response. If you need an exact count, iterate.

Returns int

toString )

Render all headers at once

This method handles the normal iteration of headers; it is up to the concrete classes to prepend with the appropriate status/request line.

Returns string

toArray )

Return the headers container as an array

Returns array

forceLoading )

By calling this, it will force parsing and loading of all headers, after this count() will be accurate

Returns bool


Zend\Http\Header\* Base Methods

fromString ( string $headerLine )

Factory to generate a header object from a string

Returns Zend\Http\Header\GenericHeader

getFieldName )

Retrieve header field name

Returns string

getFieldValue )

Retrieve header field value

Returns string

toString )

Cast to string as a well formed HTTP header line

Returns in form of "NAME: VALUE\r\n"

Returns string

List of Http Header Types

Zend\Http\Header\* Classes
Class Name Additional Methods
Accept N/A
AcceptCharset N/A
AcceptEncoding N/A
AcceptLanguage N/A

getRangeUnit() / setRangeUnit() - The range unit of the accept ranges header

Age getDeltaSeconds() / setDeltaSeconds() - The age in delta seconds
Allow getAllowedMethods() / setAllowedMethods() - An array of allowed methods
AuthenticationInfo N/A
Authorization N/A
CacheControl N/A
Connection N/A
ContentDisposition N/A
ContentEncoding N/A
ContentLanguage N/A
ContentLength N/A
ContentLocation N/A
ContentMD5 N/A
ContentRange N/A
ContentType N/A

Extends \ArrayObject

setEncodeValue() / getEncodeValue() - Whether or not to encode values

Date N/A
Etag N/A
Expect N/A
Expires N/A
From N/A
Host N/A
IfMatch N/A
IfModifiedSince N/A
IfNoneMatch N/A
IfRange N/A
IfUnmodifiedSince N/A
KeepAlive N/A
LastModified N/A
Location N/A
MaxForwards N/A
Pragma N/A
ProxyAuthenticate N/A
ProxyAuthorization N/A
Range N/A
Referer N/A
Refresh N/A
RetryAfter N/A
Server N/A

getName() / setName() - The cookies name

getValue() / setValue() - The cookie value

getDomain() / setDomain() - The domain the cookie applies to

getExpires() / setExpires() - The time frame the cookie is valid for, null is a session cookie

getPath() / setPath() - The uri path the cookie is bound to

isSecure() / setSecure() - Whether the cookies contains the Secure flag

isHttponly() / setHttponly() - Whether the cookies can be accessed via HTTP only

Trailer N/A
TransferEncoding N/A
Upgrade N/A
UserAgent N/A
Vary N/A
Via N/A
Warning N/A
WWWAuthenticate N/A
Previous Next