HTTP
class HTTP
A class with HTTP-related helpers. Like Debug, this is more a bundle of methods than a class.
Traits
Config options
cache_ajax_requests | bool | ||
disable_http_cache | bool | ||
MimeTypes | array | Mapping of extension to mime types | |
cache_control | array | List of names to add to the Cache-Control header. | |
vary | string|null | Vary string; A comma separated list of var header names |
Methods
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .
Gets the uninherited value for the given config option
Turns a local system filename into a URL by comparing it to the script filename.
Turn all relative URLs in the content to absolute URLs.
Rewrite all the URLs in the given content, evaluating the given string as PHP code.
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.
No description
Search for all tags with a specific attribute, then return the value of that attribute in a flat array.
No description
No description
Get the MIME type based on a file's extension. If the finfo class exists in PHP, and the file exists relative to the project root, then use that extension, otherwise fallback to a list of commonly known MIME types.
Add the appropriate caching headers to the response, including If-Modified-Since / 304 handling.
Ensure that all deprecated HTTP cache settings are respected
Return an {@link http://www.faqs.org/rfcs/rfc2822 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 static variable cache_age in second
Details
in Configurable at line 20
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .
....).
in Configurable at line 32
mixed
stat(string $name)
deprecated
deprecated 5.0 Use ->config()->get() instead
Get inherited config value
in Configurable at line 44
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
in Configurable at line 57
$this
set_stat(string $name, mixed $value)
deprecated
deprecated 5.0 Use ->config()->set() instead
Update the config value for a given property
at line 96
static string
filename2url(string $filename)
Turns a local system filename into a URL by comparing it to the script filename.
at line 121
static string
absoluteURLs(string $html)
Turn all relative URLs in the content to absolute URLs.
at line 157
static string
urlRewriter(string $content, callable $code)
Rewrite all the URLs in the given content, evaluating the given string as PHP code.
Put $URL where you want the URL to appear, however, you can't embed $URL in strings, for example:
'"../../" . $URL'
'myRewriter($URL)'
'(substr($URL, 0, 1)=="/") ? "../" . substr($URL, 1) : $URL'
As of 3.2 $code should be a callable which takes a single parameter and returns the rewritten,
for example:
function($url) {
return Director::absoluteURL($url, true);
}
at line 220
static string
setGetVar(string $varname, string $varvalue, string|null $currentURL = null, string $separator = '&')
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.
at line 284
static string
RAW_setGetVar(string $varname, string $varvalue, null|string $currentURL = null)
at line 299
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.
at line 326
static array
getLinksIn(string $content)
at line 336
static array
getImagesIn(string $content)
at line 349
static string
get_mime_type(string $filename)
Get the MIME type based on a file's extension. If the finfo class exists in PHP, and the file exists relative to the project root, then use that extension, otherwise fallback to a list of commonly known MIME types.
at line 378
static
set_cache_age(int $age)
deprecated
deprecated 4.2.0:5.0.0 Use HTTPCacheControlMiddleware::singleton()->setMaxAge($age) instead
Set the maximum age of this page in web caches, in seconds.
at line 389
static
register_modification_date(string $dateString)
deprecated
deprecated 4.2.0:5.0.0 Use HTTPCacheControlMiddleware::registerModificationDate() instead
at line 399
static
register_modification_timestamp(int $timestamp)
deprecated
deprecated 4.2.0:5.0.0 Use HTTPCacheControlMiddleware::registerModificationDate() instead
at line 409
static
register_etag(string $etag)
deprecated
deprecated 4.2.0:5.0.0 Use ChangeDetectionMiddleware instead
at line 431
static
add_cache_headers(HTTPResponse $response = null)
deprecated
deprecated 4.2.0:5.0.0 Headers are added automatically by HTTPCacheControlMiddleware instead.
Add the appropriate caching headers to the response, including If-Modified-Since / 304 handling.
Note that setting HTTP::$cache_age will overrule any cache headers set by PHP's session_cache_limiter functionality. It is your responsibility to ensure only cacheable data is in fact cached, and HTTP::$cache_age isn't set when the HTTP body contains session-specific content.
Omitting the $body argument or passing a string is deprecated; in these cases, the headers are output directly.
at line 481
static
augmentState(HTTPRequest $request, HTTPResponse $response)
deprecated
deprecated 4.2.0:5.0.0 Use HTTPCacheControlMiddleware instead
Ensure that all deprecated HTTP cache settings are respected
at line 566
static string
gmt_date(int $timestamp)
deprecated
deprecated 4.2.0:5.0.0 Inline if you need this
Return an {@link http://www.faqs.org/rfcs/rfc2822 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)
at line 576
static int
get_cache_age()
Return static variable cache_age in second