anterior  
índice  
siguiente  
Updated 2012-10-02 - Version ZF 2.0.3

Zend\Http\Headers And The Various Header Classes

Overview

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

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

setPluginClassLoader(Zend\Loader\PluginClassLocator $pluginClassLoader)

Set an alternate implementation for the plugin class loader

Returns Zend\Http\Headers

getPluginClassLoader

getPluginClassLoader()

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

Returns Zend\Loader\PluginClassLocator

addHeaders

addHeaders(array|Traversable $headers)

Add many headers at once

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

Returns Zend\Http\Headers

addHeaders

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

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

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

Returns Zend\Http\Headers

removeHeader

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

Remove a Header from the container

Returns bool

clearHeaders

clearHeaders()

Clear all headers

Removes all headers from queue

Returns Zend\Http\Headers

get

get(string $name)

Get all headers of a certain name/type

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

has

has(string $name)

Test for existence of a type of header

Returns bool

next

next()

Advance the pointer for this object as an interator

Returns void

key

key()

Return the current key for this object as an interator

Returns mixed

valid

valid()

Is this iterator still valid?

Returns bool

rewind

rewind()

Reset the internal pointer for this object as an iterator

Returns void

current

current()

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

Returns Zend\Http\Header\HeaderInterface

count

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

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

toArray()

Return the headers container as an array

Returns array

forceLoading

forceLoading()

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

Returns bool

Examples

Zend\Http\Header\* Base Methods

fromString

fromString(string $headerLine)

Factory to generate a header object from a string

Returns Zend\Http\Header\GenericHeader

getFieldName

getFieldName()

Retrieve header field name

Returns string

getFieldValue

getFieldValue()

Retrieve header field value

Returns string

toString

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
AcceptRanges 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
Cookie Extends \ArrayObjectsetEncodeValue() / 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
SetCookie getName() / setName() - The cookies namegetValue() / setValue() - The cookie valuegetDomain() / setDomain() - The domain the cookie applies togetExpires() / setExpires() - The time frame the cookie is valid for, null is a session cookiegetPath() / setPath() - The uri path the cookie is bound toisSecure() / setSecure() - Whether the cookies contains the Secure flagisHttponly() / setHttponly() - Whether the cookies can be accessed via HTTP only
TE N/A
Trailer N/A
TransferEncoding N/A
Upgrade N/A
UserAgent N/A
Vary N/A
Via N/A
Warning N/A
WWWAuthenticate N/A
Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Zend\Http\Headers And The Various Header Classes on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.