Version: current

# Class HTTP

A class with HTTP-related helpers. Like Debug, this is more a bundle of methods than a class ;-)

Package: sapphire\misc
Located at sapphire/core/HTTP.php

## Methods summary

`public static` | # `filename2url( mixed $filename )` Turns a local system filename into a URL by comparing it to the script filename Turns a local system filename into a URL by comparing it to the script filename
`public static` | # `absoluteURLs( mixed $html )` Turn all relative URLs in the content to absolute URLs Turn all relative URLs in the content to absolute URLs
`public static` | # `urlRewriter( mixed $content, mixed $code )`
`public static String` | # `setGetVar( String $varname, String $varvalue, String $currentURL = null, String $separator = '&amp;' )` Will try to include a GET parameter for an existing URL, preserving existing parameters and fragments. If no URL is given, falls back to $_SERVER['REQUEST_URI']. Uses parse_url() to dissect the URL, and http_build_query() to reconstruct it with the additional parameter. Converts any '&' (ampersand) URL parameter separators to the more XHTML compliant '&'. Will try to include a GET parameter for an existing URL, preserving existing parameters and fragments. If no URL is given, falls back to $_SERVER['REQUEST_URI']. Uses parse_url() to dissect the URL, and http_build_query() to reconstruct it with the additional parameter. Converts any '&' (ampersand) URL parameter separators to the more XHTML compliant '&'. CAUTION: If the URL is determined to be relative, it is prepended with Director::absoluteBaseURL(). This method will always return an absolute URL because Director::makeRelative() can lead to inconsistent results. #### Parameters $varname String $varname $varvalue String $varvalue $currentURL String $currentURL Relative or absolute URL (Optional). $separator String $separator Separator for http_build_query(). (Optional). #### Returns `String` Absolute URL
`public static` | # `RAW_setGetVar( mixed $varname, mixed $varvalue, mixed $currentURL = null )`
`public static array` | # `findByTagAndAttribute( string $content, array $attributes )` Search for all tags with a specific attribute, then return the value of that attribute in a flat array. Search for all tags with a specific attribute, then return the value of that attribute in a flat array. #### Parameters $content string $content $attributes array $attributes an array of tags to attributes, for example "[a] => 'href', [div] => 'id'" #### Returns `array` array
`public static` | # `getLinksIn( mixed $content )`
`public static` | # `getImagesIn( mixed $content )`
`public static` | # `getMimeType( mixed $filename )`
`public static` | # `loadMimeTypes( )`
`public static String` | # `sendRequest( mixed $host, mixed $path, mixed $query, mixed $port = 80 )` Send an HTTP request to the host. Send an HTTP request to the host. #### Returns `String` Response text
`public static string` | # `sendPostRequest( string $host, string $path, array|string $data, string $name = null, string $query = '', string $port = 80, mixed $getResponse = true )` Send a HTTP POST request through fsockopen(). Send a HTTP POST request through fsockopen(). #### Parameters $host string $host Absolute URI without path, e.g. http://silverstripe.com $path string $path Path with leading slash $data array|string $data Payload for the request $name string $name Parametername for the payload (only if passed as a string) $query string $query $port string $port $getResponse #### Returns `string` Raw HTTP-result including headers
`public static` | # `set_cache_age( mixed $age )` Set the maximum age of this page in web caches, in seconds Set the maximum age of this page in web caches, in seconds
`public static` | # `register_modification_date( mixed $dateString )`
`public static` | # `register_modification_timestamp( mixed $timestamp )`
`public static` | # `register_etag( mixed $etag )`
`public static` | # `add_cache_headers( `SS_HTTPResponse` $body = null )` Add the appropriate caching headers to the response, including If-Modified-Since / 304 handling. Add the appropriate caching headers to the response, including If-Modified-Since / 304 handling. #### Parameters $body SS_HTTPResponse The SS_HTTPResponse object to augment. Omitted the argument or passing a string is deprecated; in these cases, the headers are output directly.
`public static` | # `gmt_date( mixed $timestamp )` Return an RFC 2822 date in the GMT timezone (a timestamp is always in GMT: the number of seconds since January 1 1970 00:00:00 GMT) Return an RFC 2822 date in the GMT timezone (a timestamp is always in GMT: the number of seconds since January 1 1970 00:00:00 GMT)
`public static` | # `get_cache_age( )`

### Magic methods summary

## Properties summary

`public static mixed` | $userName | #
`public static mixed` | $password | #
`protected static integer` | $cache_age | #
`protected static mixed` | $modification_date | #
`protected static mixed` | $etag | #

[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. -