Version: current

# Class SS_HTTPRequest

Represents a HTTP-request, including a URL that is tokenised for parsing, and a request method (GET/POST/PUT/DELETE). This is used by `RequestHandler` objects to decide what to do.

The intention is that a single SS_HTTPRequest object can be passed from one object to another, each object calling match() to get the information that they need out of the URL. This is generally handled by `RequestHandler::handleRequest()`.

  SS_HTTPRequest implements ArrayAccess

Package: sapphire\control
Used by: ``RequestHandler::handleRequest()``
Located at sapphire/core/control/HTTPRequest.php

## Methods summary

`public` | # `__construct( mixed $httpMethod, mixed $url, mixed $getVars = array(), mixed $postVars = array(), mixed $body = null )` Construct a SS_HTTPRequest from a URL relative to the site root. Construct a SS_HTTPRequest from a URL relative to the site root.
`public` | # `isGET( )`
`public` | # `isPOST( )`
`public` | # `isPUT( )`
`public` | # `isDELETE( )`
`public` | # `isHEAD( )`
`public` | # `setBody( mixed $body )`
`public` | # `getBody( )`
`public` | # `getVars( )`
`public` | # `postVars( )`
`public array` | # `requestVars( )` Returns all combined HTTP GET and POST parameters passed into this request. If a parameter with the same name exists in both arrays, the POST value is returned. Returns all combined HTTP GET and POST parameters passed into this request. If a parameter with the same name exists in both arrays, the POST value is returned. #### Returns `array` array #### Used by ``Controller::$requestParams``
`public` | # `getVar( mixed $name )`
`public` | # `postVar( mixed $name )`
`public` | # `requestVar( mixed $name )`
`public string` | # `getExtension( )` Returns a possible file extension found in parsing the URL as denoted by a "."-character near the end of the URL. Doesn't necessarily have to belong to an existing file, for example used for `RestfulServer` content-type-switching. Returns a possible file extension found in parsing the URL as denoted by a "."-character near the end of the URL. Doesn't necessarily have to belong to an existing file, for example used for `RestfulServer` content-type-switching. #### Returns `string` string
`public boolean` | # `isMedia( )` Checks if the SS_HTTPRequest->getExtension() on this request matches one of the more common media types embedded into a webpage - e.g. css, png. Checks if the SS_HTTPRequest->getExtension() on this request matches one of the more common media types embedded into a webpage - e.g. css, png. This is useful for things like determining wether to display a fully rendered error page or not. Note that the media file types is not at all comprehensive. #### Returns `boolean` bool
`public` | # `addHeader( string $header, string $value )` Add a HTTP header to the response, replacing any header of the same name. Add a HTTP header to the response, replacing any header of the same name. #### Parameters $header string $header Example: "Content-Type" $value string $value Example: "text/xml"
`public array` | # `getHeaders( )` #### Returns `array` array
`public` | # `getHeader( string $header )` Remove an existing HTTP header Remove an existing HTTP header #### Parameters $header string $header
`public` | # `removeHeader( string $header )` Remove an existing HTTP header by its name, e.g. "Content-Type". Remove an existing HTTP header by its name, e.g. "Content-Type". #### Parameters $header string $header
`public string` | # `getURL( )` #### Returns `string` string
`public boolean` | # `offsetExists( unknown_type $offset )` Enables the existence of a key-value pair in the request to be checked using array syntax, so isset($request['title']) will check for $_POST['title'] and $_GET['title'] Enables the existence of a key-value pair in the request to be checked using array syntax, so isset($request['title']) will check for $_POST['title'] and $_GET['title'] #### Parameters $offset unknown_type $offset #### Returns `boolean` boolean #### Implementation of `ArrayAccess::offsetExists()`
`public unknown` | # `offsetGet( unknown_type $offset )` Access a request variable using array syntax. eg: $request['title'] instead of $request->postVar('title') Access a request variable using array syntax. eg: $request['title'] instead of $request->postVar('title') #### Parameters $offset unknown_type $offset #### Returns `unknown` unknown #### Implementation of `ArrayAccess::offsetGet()`
`public static` | # `send_file( mixed $fileData, mixed $fileName, mixed $mimeType = null )` Construct an SS_HTTPResponse that will deliver a file to the client Construct an SS_HTTPResponse that will deliver a file to the client
`public` | # `match( mixed $pattern, mixed $shiftOnSuccess = false )` Matches a URL pattern The pattern can contain a number of segments, separated by / (and an extension indicated by a .) Matches a URL pattern The pattern can contain a number of segments, separated by / (and an extension indicated by a .) The parts can be either literals, or, if they start with a $ they are interpreted as variables. - Literals must be provided in order to match - $Variables are optional - However, if you put ! at the end of a variable, then it becomes mandatory. For example: - admin/crm/list will match admin/crm/$Action/$ID/$OtherID, but it won't match admin/crm/$Action!/$ClassName! The pattern can optionally start with an HTTP method and a space. For example, "POST $Controller/$Action". This is used to define a rule that only matches on a specific HTTP method. #### Used by ``RequestHandler::handleRequest()``
`public` | # `allParams( )`
`public string` | # `shiftAllParams( )` Shift all the parameter values down a key space, and return the shifted value. Shift all the parameter values down a key space, and return the shifted value. #### Returns `string` string
`public` | # `latestParams( )`
`public` | # `latestParam( mixed $name )`
`public string` | # `param( string $name )` Finds a named URL parameter (denoted by "$"-prefix in $url_handlers) from the full URL. Finds a named URL parameter (denoted by "$"-prefix in $url_handlers) from the full URL. #### Parameters $name string $name #### Returns `string` Value of the URL parameter (if found)
`public string` | # `remaining( )` Returns the unparsed part of the original URL separated by commas. This is used by RequestHandler->handleRequest() to determine if further URL processing is necessary. Returns the unparsed part of the original URL separated by commas. This is used by RequestHandler->handleRequest() to determine if further URL processing is necessary. #### Returns `string` Partial URL
`public` | # `isEmptyPattern( mixed $pattern )` Returns true if this is a URL that will match without shifting off any of the URL. This is used by the request handler to prevent infinite parsing loops. Returns true if this is a URL that will match without shifting off any of the URL. This is used by the request handler to prevent infinite parsing loops.
`public` | # `shift( mixed $count = 1 )` Shift one or more parts off the beginning of the URL. If you specify shifting more than 1 item off, then the items will be returned as an array Shift one or more parts off the beginning of the URL. If you specify shifting more than 1 item off, then the items will be returned as an array
`public` | # `allParsed( )` Returns true if the URL has been completely parsed. This will respect parsed but unshifted directory parts. Returns true if the URL has been completely parsed. This will respect parsed but unshifted directory parts.
`public string` | # `getIP( )` Returns the client IP address which originated this request. Returns the client IP address which originated this request. #### Returns `string` string
`public array` | # `getAcceptMimetypes( boolean $includeQuality = false )` Returns all mimetypes from the HTTP "Accept" header as an array. Returns all mimetypes from the HTTP "Accept" header as an array. #### Parameters $includeQuality boolean $includeQuality Don't strip away optional "quality indicators", e.g. "application/xml;q=0.9" (Default: false) #### Returns `array` array
`public string` | # `httpMethod( )` #### Returns `string` HTTP method (all uppercase)
`public static string` | # `detect_method( string $origMethod, array $postVars )` Gets the "real" HTTP method for a request. Gets the "real" HTTP method for a request. Used to work around browser limitations of form submissions to GET and POST, by overriding the HTTP method with a POST parameter called "_method" for PUT, DELETE, HEAD. Using GET for the "_method" override is not supported, as GET should never carry out state changes. Alternatively you can use a custom HTTP header 'X-HTTP-Method-Override' to override the original method in `Director::direct()`. The '_method' POST parameter overrules the custom HTTP header. #### Parameters $origMethod string $origMethod Original HTTP method from the browser request $postVars array $postVars #### Returns `string` HTTP method (all uppercase)

### Methods inherited from ArrayAccess

`offsetSet()`, `offsetUnset()`

### Magic methods summary

## Properties summary

`protected string` | $url | # $url $url
`protected mixed` | $dirParts | # The non-extension parts of the passed URL as an array, originally exploded by the "/" separator. All elements of the URL are loaded in here, and subsequently popped out of the array by `SS_HTTPRequest::shift()`. Only use this structure for internal request handling purposes. The non-extension parts of the passed URL as an array, originally exploded by the "/" separator. All elements of the URL are loaded in here, and subsequently popped out of the array by `SS_HTTPRequest::shift()`. Only use this structure for internal request handling purposes.
`protected string` | $extension | # $extension The URL extension (if present) $extension The URL extension (if present)
`protected string` | $httpMethod | # $httpMethod The HTTP method in all uppercase: GET/PUT/POST/DELETE/HEAD $httpMethod The HTTP method in all uppercase: GET/PUT/POST/DELETE/HEAD
`protected array` | $getVars | # $getVars Contains alls HTTP GET parameters passed into this request. $getVars Contains alls HTTP GET parameters passed into this request.
`protected array` | $postVars | # $postVars Contains alls HTTP POST parameters passed into this request. $postVars Contains alls HTTP POST parameters passed into this request.
`protected array` | $headers | # HTTP Headers like "Content-Type: text/xml" HTTP Headers like "Content-Type: text/xml" #### See http://en.wikipedia.org/wiki/List_of_HTTP_headers
`protected string` | $body | # Raw HTTP body, used by PUT and POST requests. Raw HTTP body, used by PUT and POST requests.
`protected array` | $allParams | # $allParams Contains an assiciative array of all arguments matched in all calls to RequestHandler->handleRequest(). It's a "historical record" that's specific to the current call of handleRequest(), and is only complete once the "last call" to that method is made. $allParams Contains an assiciative array of all arguments matched in all calls to RequestHandler->handleRequest(). It's a "historical record" that's specific to the current call of handleRequest(), and is only complete once the "last call" to that method is made.
`protected array` | $latestParams | # $latestParams Contains an associative array of all arguments matched in the current call from RequestHandler->handleRequest(), as denoted with a "$"-prefix in the $url_handlers definitions. Contains different states throughout its lifespan, so just useful while processed in `RequestHandler` and to get the last processes arguments. $latestParams Contains an associative array of all arguments matched in the current call from RequestHandler->handleRequest(), as denoted with a "$"-prefix in the $url_handlers definitions. Contains different states throughout its lifespan, so just useful while processed in `RequestHandler` and to get the last processes arguments.
`protected integer` | $unshiftedButParsedParts | #

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -