Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
bcbebe39
Commit
bcbebe39
authored
13 years ago
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Document OC_Response
parent
86893ea7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/response.php
+40
-0
40 additions, 0 deletions
lib/response.php
with
40 additions
and
0 deletions
lib/response.php
+
40
−
0
View file @
bcbebe39
...
...
@@ -12,6 +12,13 @@ class OC_Response {
const
STATUS_TEMPORARY_REDIRECT
=
307
;
const
STATUS_NOT_FOUND
=
404
;
/**
* @brief Enable response caching by sending correct HTTP headers
* @param $cache_time time to cache the response
* >0 cache time in seconds
* 0 and <0 enable default browser caching
* null cache indefinitly
*/
static
public
function
enableCaching
(
$cache_time
=
null
)
{
if
(
is_numeric
(
$cache_time
))
{
header
(
'Pragma: public'
);
// enable caching in IE
...
...
@@ -30,10 +37,19 @@ class OC_Response {
}
}
/**
* @brief disable browser caching
* @see enableCaching with cache_time = 0
*/
static
public
function
disableCaching
()
{
self
::
enableCaching
(
0
);
}
/**
* @brief Set response status
* @param $status a HTTP status code, see also the STATUS constants
*/
static
public
function
setStatus
(
$status
)
{
$protocol
=
$_SERVER
[
'SERVER_PROTOCOL'
];
switch
(
$status
)
{
...
...
@@ -58,11 +74,21 @@ class OC_Response {
header
(
$protocol
.
' '
.
$status
);
}
/**
* @brief Send redirect response
* @param $location to redirect to
*/
static
public
function
redirect
(
$location
)
{
self
::
setStatus
(
self
::
STATUS_TEMPORARY_REDIRECT
);
header
(
'Location: '
.
$location
);
}
/**
* @brief Set reponse expire time
* @param $expires date-time when the response expires
* string for DateInterval from now
* DateTime object when to expire response
*/
static
public
function
setExpiresHeader
(
$expires
)
{
if
(
is_string
(
$expires
)
&&
$expires
[
0
]
==
'P'
)
{
$interval
=
$expires
;
...
...
@@ -76,6 +102,11 @@ class OC_Response {
header
(
'Expires: '
.
$expires
);
}
/**
* Checks and set ETag header, when the request matches sends a
* 'not modified' response
* @param $etag token to use for modification check
*/
static
public
function
setETagHeader
(
$etag
)
{
if
(
empty
(
$etag
))
{
return
;
...
...
@@ -88,6 +119,11 @@ class OC_Response {
header
(
'ETag: '
.
$etag
);
}
/**
* Checks and set Last-Modified header, when the request matches sends a
* 'not modified' response
* @param $lastModified time when the reponse was last modified
*/
static
public
function
setLastModifiedHeader
(
$lastModified
)
{
if
(
empty
(
$lastModified
))
{
return
;
...
...
@@ -106,6 +142,10 @@ class OC_Response {
header
(
'Last-Modified: '
.
$lastModified
);
}
/**
* @brief Send file as response, checking and setting caching headers
* @param $filepath of file to send
*/
static
public
function
sendFile
(
$filepath
=
null
)
{
$fp
=
fopen
(
$filepath
,
'rb'
);
if
(
$fp
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment