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
GitLab 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
Feb 17, 2012
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Document OC_Response
parent
86893ea7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show 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 {
...
@@ -12,6 +12,13 @@ class OC_Response {
const
STATUS_TEMPORARY_REDIRECT
=
307
;
const
STATUS_TEMPORARY_REDIRECT
=
307
;
const
STATUS_NOT_FOUND
=
404
;
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
)
{
static
public
function
enableCaching
(
$cache_time
=
null
)
{
if
(
is_numeric
(
$cache_time
))
{
if
(
is_numeric
(
$cache_time
))
{
header
(
'Pragma: public'
);
// enable caching in IE
header
(
'Pragma: public'
);
// enable caching in IE
...
@@ -30,10 +37,19 @@ class OC_Response {
...
@@ -30,10 +37,19 @@ class OC_Response {
}
}
}
}
/**
* @brief disable browser caching
* @see enableCaching with cache_time = 0
*/
static
public
function
disableCaching
()
{
static
public
function
disableCaching
()
{
self
::
enableCaching
(
0
);
self
::
enableCaching
(
0
);
}
}
/**
* @brief Set response status
* @param $status a HTTP status code, see also the STATUS constants
*/
static
public
function
setStatus
(
$status
)
{
static
public
function
setStatus
(
$status
)
{
$protocol
=
$_SERVER
[
'SERVER_PROTOCOL'
];
$protocol
=
$_SERVER
[
'SERVER_PROTOCOL'
];
switch
(
$status
)
{
switch
(
$status
)
{
...
@@ -58,11 +74,21 @@ class OC_Response {
...
@@ -58,11 +74,21 @@ class OC_Response {
header
(
$protocol
.
' '
.
$status
);
header
(
$protocol
.
' '
.
$status
);
}
}
/**
* @brief Send redirect response
* @param $location to redirect to
*/
static
public
function
redirect
(
$location
)
{
static
public
function
redirect
(
$location
)
{
self
::
setStatus
(
self
::
STATUS_TEMPORARY_REDIRECT
);
self
::
setStatus
(
self
::
STATUS_TEMPORARY_REDIRECT
);
header
(
'Location: '
.
$location
);
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
)
{
static
public
function
setExpiresHeader
(
$expires
)
{
if
(
is_string
(
$expires
)
&&
$expires
[
0
]
==
'P'
)
{
if
(
is_string
(
$expires
)
&&
$expires
[
0
]
==
'P'
)
{
$interval
=
$expires
;
$interval
=
$expires
;
...
@@ -76,6 +102,11 @@ class OC_Response {
...
@@ -76,6 +102,11 @@ class OC_Response {
header
(
'Expires: '
.
$expires
);
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
)
{
static
public
function
setETagHeader
(
$etag
)
{
if
(
empty
(
$etag
))
{
if
(
empty
(
$etag
))
{
return
;
return
;
...
@@ -88,6 +119,11 @@ class OC_Response {
...
@@ -88,6 +119,11 @@ class OC_Response {
header
(
'ETag: '
.
$etag
);
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
)
{
static
public
function
setLastModifiedHeader
(
$lastModified
)
{
if
(
empty
(
$lastModified
))
{
if
(
empty
(
$lastModified
))
{
return
;
return
;
...
@@ -106,6 +142,10 @@ class OC_Response {
...
@@ -106,6 +142,10 @@ class OC_Response {
header
(
'Last-Modified: '
.
$lastModified
);
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
)
{
static
public
function
sendFile
(
$filepath
=
null
)
{
$fp
=
fopen
(
$filepath
,
'rb'
);
$fp
=
fopen
(
$filepath
,
'rb'
);
if
(
$fp
)
{
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