Class ApiHttpPolicy
A public read is a GET or HEAD request that carries no credentials
(no Authorization or x-api-key header, no session cookie) and answers 200.
Public reads get Cache-Control: public, max-age=N, s-maxage=N,
stale-while-revalidate=S, stale-if-error=E, a matching
CDN-Cache-Control (RFC 9213), a weak ETag over the body, and
304 Not Modified for a matching If-None-Match. A public read
whose handler already set a Cache-Control keeps it (a plain
public, max-age=N is expanded the same way). Every other response
(credentials, writes, errors) is private, no-store, so a shared cache
never stores an answer that depends on who asked.
CORS: public reads answer Access-Control-Allow-Origin: * with no
credentials and no Vary: Origin, so one cached copy serves every
caller. Other requests are allowed only from getCorsAllowedOrigins()
(echoed, with Vary: Origin); preflight OPTIONS requests answer 204.
An ApiInstanceMetaData without a policy keeps the historical behaviour (no cache headers; CORS reflects any origin).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncdnCacheControl(int maxAgeSeconds) The CDN-Cache-Control value (RFC 9213) for a public read.Getter for corsAllowedOriginsbooleangetEtags()Getter for etagsintGetter for maxEtagBodyBytesGetter for publicReadMaxAgeSeconds (null = public reads get no cache headers).Getter for staleIfErrorSecondsGetter for staleWhileRevalidateSecondsbooleanisCorsAllowedOrigin(String origin) Whether an origin may make credentialed / non-public requests.publicCacheControl(int maxAgeSeconds) The Cache-Control value for a public read with the given max age.voidsetCorsAllowedOrigins(List<String> corsAllowedOrigins) Setter for corsAllowedOriginsvoidsetEtags(boolean etags) Setter for etagsvoidsetMaxEtagBodyBytes(int maxEtagBodyBytes) Setter for maxEtagBodyBytesvoidsetPublicReadMaxAgeSeconds(Integer publicReadMaxAgeSeconds) Setter for publicReadMaxAgeSecondsvoidsetStaleIfErrorSeconds(Integer staleIfErrorSeconds) Setter for staleIfErrorSecondsvoidsetStaleWhileRevalidateSeconds(Integer staleWhileRevalidateSeconds) Setter for staleWhileRevalidateSecondswithCorsAllowedOrigins(List<String> corsAllowedOrigins) Fluent setter for corsAllowedOriginswithEtags(boolean etags) Fluent setter for etagswithMaxEtagBodyBytes(int maxEtagBodyBytes) Fluent setter for maxEtagBodyByteswithPublicReadMaxAgeSeconds(Integer publicReadMaxAgeSeconds) Fluent setter for publicReadMaxAgeSecondswithStaleIfErrorSeconds(Integer staleIfErrorSeconds) Fluent setter for staleIfErrorSecondswithStaleWhileRevalidateSeconds(Integer staleWhileRevalidateSeconds) Fluent setter for staleWhileRevalidateSeconds
-
Field Details
-
CORS_ALLOWED_HEADERS
-
CORS_EXPOSED_HEADERS
-
CORS_MAX_AGE_SECONDS
public static final int CORS_MAX_AGE_SECONDS- See Also:
-
-
Constructor Details
-
ApiHttpPolicy
public ApiHttpPolicy()
-
-
Method Details
-
publicCacheControl
The Cache-Control value for a public read with the given max age. -
cdnCacheControl
The CDN-Cache-Control value (RFC 9213) for a public read. -
isCorsAllowedOrigin
Whether an origin may make credentialed / non-public requests. -
getPublicReadMaxAgeSeconds
Getter for publicReadMaxAgeSeconds (null = public reads get no cache headers). -
setPublicReadMaxAgeSeconds
Setter for publicReadMaxAgeSeconds -
withPublicReadMaxAgeSeconds
Fluent setter for publicReadMaxAgeSeconds -
getStaleWhileRevalidateSeconds
Getter for staleWhileRevalidateSeconds -
setStaleWhileRevalidateSeconds
Setter for staleWhileRevalidateSeconds -
withStaleWhileRevalidateSeconds
Fluent setter for staleWhileRevalidateSeconds -
getStaleIfErrorSeconds
Getter for staleIfErrorSeconds -
setStaleIfErrorSeconds
Setter for staleIfErrorSeconds -
withStaleIfErrorSeconds
Fluent setter for staleIfErrorSeconds -
getEtags
public boolean getEtags()Getter for etags -
setEtags
public void setEtags(boolean etags) Setter for etags -
withEtags
Fluent setter for etags -
getMaxEtagBodyBytes
public int getMaxEtagBodyBytes()Getter for maxEtagBodyBytes -
setMaxEtagBodyBytes
public void setMaxEtagBodyBytes(int maxEtagBodyBytes) Setter for maxEtagBodyBytes -
withMaxEtagBodyBytes
Fluent setter for maxEtagBodyBytes -
getCorsAllowedOrigins
-
setCorsAllowedOrigins
-
withCorsAllowedOrigins
Fluent setter for corsAllowedOrigins
-