Skip to content

Commit a521e10

Browse files
authored
Merge pull request #7 from koriym/more-headers
Add stale* headers
2 parents b8d0b27 + 49e63b9 commit a521e10

File tree

8 files changed

+186
-218
lines changed

8 files changed

+186
-218
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Akihito Koriyama
3+
Copyright (c) 2015-2021 Akihito Koriyama
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "koriym/http-constants",
33
"description":"Constants for the HTTP protocol",
44
"require": {
5-
"php": ">=5.3.0"
5+
"php": ">=7.1.0"
66
},
77
"keywords":[
88
"http",

src/CacheControl.php

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,54 @@
11
<?php
22

3-
/**
4-
* This file is part of the Koriym.HttpConstants.
5-
*
6-
* @license http://opensource.org/licenses/MIT MIT
7-
*/
83
namespace Koriym\HttpConstants;
94

105
/**
116
* Cache control response directive
127
*/
138
final class CacheControl
149
{
15-
/**
16-
* Indicates that the response may be cached by any cache.
17-
*/
18-
const PUBLIC_ = 'public';
10+
/** Indicates that the response may be cached by any cache. */
11+
public const PUBLIC_ = 'public';
1912

20-
/**
21-
* Indicates that the response is intended for a single user and must not be stored by a shared cache. A private cache may store the response.
22-
*/
23-
const PRIVATE_ = 'private';
13+
/** Indicates that the response is intended for a single user and must not be stored by a shared cache. A private cache may store the response. */
14+
public const PRIVATE_ = 'private';
2415

25-
/**
26-
* Specifies the maximum amount of time a resource will be considered fresh. Contrary to Expires, this directive is relative to the time of the request.
27-
*/
28-
const MAX_AGE = 'max-age';
16+
/** Specifies the maximum amount of time a resource will be considered fresh. Contrary to Expires, this directive is relative to the time of the request. */
17+
public const MAX_AGE = 'max-age';
2918

30-
/**
31-
* Takes precedence over max-age or the Expires header, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache.
32-
*/
33-
const S_MAX_AGE = 's-maxage';
19+
/** Takes precedence over max-age or the Expires header, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache. */
20+
public const S_MAX_AGE = 's-maxage';
3421

35-
/**
36-
* Forces caches to submit the request to the origin server for validation before releasing a cached copy.
37-
*/
38-
const NO_CACHE = 'no-cache';
22+
/** Forces caches to submit the request to the origin server for validation before releasing a cached copy. */
23+
public const NO_CACHE = 'no-cache';
3924

40-
/**
41-
* The cache should not store anything about the client request or server response.
42-
*/
43-
const NO_STORE = 'no-store';
25+
/** The cache should not store anything about the client request or server response. */
26+
public const NO_STORE = 'no-store';
27+
28+
/** The cache must verify the status of the stale resources before using it and expired ones should not be used. */
29+
public const MUST_REVALIDATE = 'must-revalidate';
30+
31+
/** Same as must-revalidate, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache. */
32+
public const PROXY_REVALIDATE = 'proxy-revalidate';
4433

4534
/**
46-
* The cache must verify the status of the stale resources before using it and expired ones should not be used.
35+
* Indicates that the response body will not change over time. (for web browser)
36+
*
37+
* @see http://bitsup.blogspot.com/2016/05/cache-control-immutable.html
4738
*/
48-
const MUST_REVALIDATE = 'must-revalidate';
39+
public const IMMUTABLE = 'immutable';
4940

5041
/**
51-
* Same as must-revalidate, but it only applies to shared caches (e.g., proxies) and is ignored by a private cache.
42+
* When present in an HTTP response, the stale-while-revalidate Cache-Control extension indicates that caches MAY serve the response in which it appears after it becomes stale, up to the indicated number of seconds.
43+
*
44+
* @link https://datatracker.ietf.org/doc/html/rfc5861#section-3
5245
*/
53-
const PROXY_REVALIDATE = 'proxy-revalidate';
46+
public const STALE_WHILE_REVALIDATE = 'stale-while-revalidate';
5447

5548
/**
56-
* Indicates that the response body will not change over time. (for web browser)
49+
* The stale-if-error Cache-Control extension indicates that when an error is encountered, a cached stale response MAY be used to satisfythe request, regardless of other freshness information.
5750
*
58-
* @see http://bitsup.blogspot.com/2016/05/cache-control-immutable.html
51+
* @link https://datatracker.ietf.org/doc/html/rfc5861#section-4
5952
*/
60-
const IMMUTABLE = 'immutable';
53+
public const STALE_IF_ERROR = 'stale-if-error';
6154
}

src/MediaType.php

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
<?php
22

3-
/**
4-
* This file is part of the Koriym.HttpConstants.
5-
*
6-
* @license http://opensource.org/licenses/MIT MIT
7-
*/
83
namespace Koriym\HttpConstants;
94

105
final class MediaType
116
{
127
// generic
13-
const MULTIPART_FORM_DATA = 'multipart/form-data';
14-
const TEXT_PLAIN = 'text/plain';
15-
const TEXT_XML = 'text/xml';
16-
const TEXT_HTML = 'text/html';
17-
const WILDCARD = "*/*";
8+
public const MULTIPART_FORM_DATA = 'multipart/form-data';
9+
public const TEXT_PLAIN = 'text/plain';
10+
public const TEXT_XML = 'text/xml';
11+
public const TEXT_HTML = 'text/html';
12+
public const WILDCARD = "*/*";
1813

1914
// application
20-
const APPLICATION_ATOM_XML = "application/atom+xml";
21-
const APPLICATION_FORM_URLENCODED = 'application/x-www-form-urlencoded';
22-
const APPLICATION_JSON = 'application/json';
23-
const APPLICATION_XML = 'application/xml';
24-
const APPLICATION_SVG_XML = 'application/svg+xml';
25-
const APPLICATION_XHTML_XML = "application/xhtml+xml";
26-
const APPLICATION_RDF_XML = "application/rdf+xml";
27-
const APPLICATION_OCTET_STREAM = 'application/octet-stream';
15+
public const APPLICATION_ATOM_XML = "application/atom+xml";
16+
public const APPLICATION_FORM_URLENCODED = 'application/x-www-form-urlencoded';
17+
public const APPLICATION_JSON = 'application/json';
18+
public const APPLICATION_XML = 'application/xml';
19+
public const APPLICATION_SVG_XML = 'application/svg+xml';
20+
public const APPLICATION_XHTML_XML = "application/xhtml+xml";
21+
public const APPLICATION_RDF_XML = "application/rdf+xml";
22+
public const APPLICATION_OCTET_STREAM = 'application/octet-stream';
2823

2924
// JSON hyper media
30-
const APPLICATION_HAL = 'application/hal+json';
31-
const APPLICATION_JSON_API = 'application/vnd.api+json';
32-
const APPLICATION_JSON_LD = 'application/ld+json';
33-
const APPLICATION_COLLECTION_JSON = 'application/vnd.collection+json';
34-
const APPLICATION_SIREN = 'application/vnd.siren+json';
35-
const APPLICATION_UBER = 'application/vnd.uber+json';
25+
public const APPLICATION_HAL = 'application/hal+json';
26+
public const APPLICATION_JSON_API = 'application/vnd.api+json';
27+
public const APPLICATION_JSON_LD = 'application/ld+json';
28+
public const APPLICATION_COLLECTION_JSON = 'application/vnd.collection+json';
29+
public const APPLICATION_SIREN = 'application/vnd.siren+json';
30+
public const APPLICATION_UBER = 'application/vnd.uber+json';
3631
}

src/Method.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the Koriym.HttpConstants.
5-
*
6-
* @license http://opensource.org/licenses/MIT MIT
7-
*/
83
namespace Koriym\HttpConstants;
94

105
/**
@@ -14,15 +9,15 @@
149
*/
1510
final class Method
1611
{
17-
const POST = 'POST';
18-
const GET = 'GET';
19-
const OPTIONS = 'OPTIONS';
20-
const HEAD = 'HEAD';
21-
const PUT = 'PUT';
22-
const DELETE = 'DELETE';
23-
const TRACE = 'TRACE';
24-
const CONNECT = 'CONNECT';
25-
const PATCH = 'PATCH';
26-
const LINK = 'LINK';
27-
const UNLINK = 'UNLINK';
12+
public const POST = 'POST';
13+
public const GET = 'GET';
14+
public const OPTIONS = 'OPTIONS';
15+
public const HEAD = 'HEAD';
16+
public const PUT = 'PUT';
17+
public const DELETE = 'DELETE';
18+
public const TRACE = 'TRACE';
19+
public const CONNECT = 'CONNECT';
20+
public const PATCH = 'PATCH';
21+
public const LINK = 'LINK';
22+
public const UNLINK = 'UNLINK';
2823
}

src/RequestHeader.php

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the Koriym.HttpConstants.
5-
*
6-
* @license http://opensource.org/licenses/MIT MIT
7-
*/
83
namespace Koriym\HttpConstants;
94

105
/**
@@ -13,47 +8,47 @@
138
final class RequestHeader
149
{
1510
// Standard (RFC) Request Fields
16-
const ACCEPT = 'Accept';
17-
const ACCEPT_CHARSET = 'Accept-Charset';
18-
const ACCEPT_ENCODING = 'Accept-Encoding';
19-
const ACCEPT_LANGUAGE = 'Accept-Language';
20-
const ACCEPT_DATETIME = 'Accept-Datetime';
21-
const AUTHORIZATION = 'Authorization';
22-
const CACHE_CONTROL = 'Cache-Control';
23-
const CONNECTION = 'Connection';
24-
const CONTENT_TYPE = 'Content-Type';
25-
const COOKIE = 'Cookie';
26-
const CONTENT_LENGTH = 'Content-Length';
27-
const CONTENT_MD5 = 'Content-MD5';
28-
const DATE = 'Date';
29-
const EXPECT = 'Expect';
30-
const FROM = 'From';
31-
const HOST = 'Host';
32-
const IF_MATCH = 'If-Match';
33-
const IF_MODIFIED_SINCE = 'If-Modified-Since';
34-
const IF_NONE_MATCH = 'If-None-Matched';
35-
const IF_RANGE = 'If-Range';
36-
const IF_UNMODIFIED_SINCE = 'If-Unmodified-Since';
37-
const MAX_FORWARDS = 'Max-Forwards';
38-
const ORIGIN = 'Origin';
39-
const PRAGMA = 'Pragma';
40-
const PROXY_AUTHORIZATION = 'Proxy-Authorization';
41-
const RANGE = 'Range';
42-
const REFERER = 'Referer';
43-
const TE = 'TE';
44-
const UPGRADE = 'Upgrade';
45-
const USER_AGENT = 'User-Agent';
46-
const VIA = 'Via';
47-
const WARNING = 'Warning';
11+
public const ACCEPT = 'Accept';
12+
public const ACCEPT_CHARSET = 'Accept-Charset';
13+
public const ACCEPT_ENCODING = 'Accept-Encoding';
14+
public const ACCEPT_LANGUAGE = 'Accept-Language';
15+
public const ACCEPT_DATETIME = 'Accept-Datetime';
16+
public const AUTHORIZATION = 'Authorization';
17+
public const CACHE_CONTROL = 'Cache-Control';
18+
public const CONNECTION = 'Connection';
19+
public const COOKIE = 'Cookie';
20+
public const CONTENT_LENGTH = 'Content-Length';
21+
public const CONTENT_MD5 = 'Content-MD5';
22+
public const DATE = 'Date';
23+
public const EXPECT = 'Expect';
24+
public const FROM = 'From';
25+
public const HOST = 'Host';
26+
public const IF_MATCH = 'If-Match';
27+
public const IF_MODIFIED_SINCE = 'If-Modified-Since';
28+
public const IF_NONE_MATCH = 'If-None-Matched';
29+
public const IF_RANGE = 'If-Range';
30+
public const IF_UNMODIFIED_SINCE = 'If-Unmodified-Since';
31+
public const MAX_FORWARDS = 'Max-Forwards';
32+
public const ORIGIN = 'Origin';
33+
public const PRAGMA = 'Pragma';
34+
public const PROXY_AUTHORIZATION = 'Proxy-Authorization';
35+
public const RANGE = 'Range';
36+
public const REFERER = 'Referer';
37+
public const TE = 'TE';
38+
public const UPGRADE = 'Upgrade';
39+
public const USER_AGENT = 'User-Agent';
40+
public const VIA = 'Via';
41+
public const WARNING = 'Warning';
42+
4843
// Common Non-Standard Request Fields
49-
const DNT = 'DNT';
50-
const FRONT_END_HTTPS = 'Front-End-Https';
51-
const PROXY_CONNECTION = 'Proxy-Connection';
52-
const X_CSRF_TOKEN = 'X-Csrf-Token';
53-
const X_FORWARDED_FOR = 'X-Forwarded-For';
54-
const X_FORWARDED_HOSTS = 'X-Forwarded-For';
55-
const X_FORWARDED_PROTO = 'X-Forwarded-Proto';
56-
const X_HTTP_METHOD_OVERRIDE = 'X-Http-Method-Override';
57-
const X_REQUESTED_WITH = 'X-Requested-With';
58-
const X_WAP_PROFILE = 'X-Wap-Profile';
44+
public const DNT = 'DNT';
45+
public const FRONT_END_HTTPS = 'Front-End-Https';
46+
public const PROXY_CONNECTION = 'Proxy-Connection';
47+
public const X_CSRF_TOKEN = 'X-Csrf-Token';
48+
public const X_FORWARDED_FOR = 'X-Forwarded-For';
49+
public const X_FORWARDED_HOSTS = 'X-Forwarded-For';
50+
public const X_FORWARDED_PROTO = 'X-Forwarded-Proto';
51+
public const X_HTTP_METHOD_OVERRIDE = 'X-Http-Method-Override';
52+
public const X_REQUESTED_WITH = 'X-Requested-With';
53+
public const X_WAP_PROFILE = 'X-Wap-Profile';
5954
}

src/ResponseHeader.php

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the Koriym.HttpConstants.
5-
*
6-
* @license http://opensource.org/licenses/MIT MIT
7-
*/
83
namespace Koriym\HttpConstants;
94

105
/**
@@ -19,45 +14,45 @@
1914
final class ResponseHeader
2015
{
2116
// Standard (RFC) Response Fields
22-
const ACCESS_CONTROL_ALLOW_ORIGIN = 'Access-Control-Allow-Origin';
23-
const ACCEPT_PATCH = 'Accept-Patch';
24-
const ACCEPT_RANGES = 'Accept-Ranges';
25-
const AGE = 'Age';
26-
const ALLOW = 'Allow';
27-
const CACHE_CONTROL = 'Cache-Control';
28-
const CONNECTION = 'Connection';
29-
const CONTENT_DISPOSITION = 'Content-Disposition';
30-
const CONTENT_ENCODING = 'Content-Encoding';
31-
const CONTENT_LANGUAGE = 'Content-Language';
32-
const CONTENT_LENGTH = 'Content-Length';
33-
const CONTENT_LOCATION = 'Content-Location';
34-
const CONTENT_MD5 = 'Content-MD5';
35-
const CONTENT_TYPE = 'Content-Type';
36-
const DATE = 'Date';
37-
const ETAG = 'ETag';
38-
const EXPIRES = 'Expires';
39-
const LAST_MODIFIED = 'Last-Modified';
40-
const LOCATION = 'Location';
41-
const P3P = 'P3P';
42-
const PROXY_AUTHENTICATE = 'Proxy-Authenticate';
43-
const PUBLIC_KEY_PINS = 'Public-Key-Pins';
44-
const REFRESH = 'Refresh';
45-
const RETRY_AFTER = 'Retry-After';
46-
const SERVER = 'Server';
47-
const SET_COOKIE = 'Set-Cookie';
48-
const STATUS = 'Status';
49-
const STRICT_TRANSPORT_SECURITY = 'Strict-Transport-Security';
50-
const TRAILER = 'Trailer';
51-
const TRANSFER_ENCODING = 'Transfer-Encoding';
52-
const UPGRADE = 'Upgrade';
53-
const VARY = 'Vary';
54-
const WARNING = 'Warning';
55-
const WWW_AUTHENTICATE = 'WWW-Authenticate';
17+
public const ACCESS_CONTROL_ALLOW_ORIGIN = 'Access-Control-Allow-Origin';
18+
public const ACCEPT_PATCH = 'Accept-Patch';
19+
public const ACCEPT_RANGES = 'Accept-Ranges';
20+
public const AGE = 'Age';
21+
public const ALLOW = 'Allow';
22+
public const CACHE_CONTROL = 'Cache-Control';
23+
public const CONNECTION = 'Connection';
24+
public const CONTENT_DISPOSITION = 'Content-Disposition';
25+
public const CONTENT_ENCODING = 'Content-Encoding';
26+
public const CONTENT_LANGUAGE = 'Content-Language';
27+
public const CONTENT_LENGTH = 'Content-Length';
28+
public const CONTENT_LOCATION = 'Content-Location';
29+
public const CONTENT_MD5 = 'Content-MD5';
30+
public const CONTENT_TYPE = 'Content-Type';
31+
public const DATE = 'Date';
32+
public const ETAG = 'ETag';
33+
public const EXPIRES = 'Expires';
34+
public const LAST_MODIFIED = 'Last-Modified';
35+
public const LOCATION = 'Location';
36+
public const P3P = 'P3P';
37+
public const PROXY_AUTHENTICATE = 'Proxy-Authenticate';
38+
public const PUBLIC_KEY_PINS = 'Public-Key-Pins';
39+
public const REFRESH = 'Refresh';
40+
public const RETRY_AFTER = 'Retry-After';
41+
public const SERVER = 'Server';
42+
public const SET_COOKIE = 'Set-Cookie';
43+
public const STATUS = 'Status';
44+
public const STRICT_TRANSPORT_SECURITY = 'Strict-Transport-Security';
45+
public const TRAILER = 'Trailer';
46+
public const TRANSFER_ENCODING = 'Transfer-Encoding';
47+
public const UPGRADE = 'Upgrade';
48+
public const VARY = 'Vary';
49+
public const WARNING = 'Warning';
50+
public const WWW_AUTHENTICATE = 'WWW-Authenticate';
5651
// Common Non-Standard Request Fields
57-
const CONTENT_SECURITY_POLICY = 'Content-Security-Policy';
58-
const X_XSS_PROTECTION = 'X-XSS-Protection';
59-
const X_CONTENT_TYPE_OPTIONS = 'X-Content-Type-Options';
60-
const X_POWERED_BY = 'X-Powered-By';
61-
const X_UA_COMPATIBLE = 'X-UA-Compatible';
62-
const X_CONTENT_DURATION = 'X-Content-Duration';
52+
public const CONTENT_SECURITY_POLICY = 'Content-Security-Policy';
53+
public const X_XSS_PROTECTION = 'X-XSS-Protection';
54+
public const X_CONTENT_TYPE_OPTIONS = 'X-Content-Type-Options';
55+
public const X_POWERED_BY = 'X-Powered-By';
56+
public const X_UA_COMPATIBLE = 'X-UA-Compatible';
57+
public const X_CONTENT_DURATION = 'X-Content-Duration';
6358
}

0 commit comments

Comments
 (0)