Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class HeadersConfigurer

  1. Object
  2. SecurityConfigurer
  3. HeadersConfigurer

The security headers a chain puts on its responses. On by default:

X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Strict-Transport-Security: max-age=31536000 ; includeSubDomains

The cache headers are left out when the handler set any of the three itself, and the last header is sent only on a response to a request that arrived over TLS this server terminated. A header the handler set is never replaced.

http.headers(headers -> headers
        .frameOptions(frame -> frame.sameOrigin())
        .contentSecurityPolicy(csp -> csp.policyDirectives("default-src 'self'")));

Nested types

class HeadersConfigurer.ToggleA header that is either sent or not.
class HeadersConfigurer.FrameOptionsConfigX-Frame-Options.
class HeadersConfigurer.HstsConfigStrict-Transport-Security.
class HeadersConfigurer.ContentSecurityPolicyConfigContent-Security-Policy.

Methods

public HeadersConfigurer defaultsDisabled()Turns every default off, leaving what is configured after this call.
public HeadersConfigurer frameOptions(Customizer<HeadersConfigurer.FrameOptionsConfig> frameOptionsCustomizer)X-Frame-Options: whether a page may be shown in a frame.
public HeadersConfigurer httpStrictTransportSecurity(Customizer<HeadersConfigurer.HstsConfig> hstsCustomizer)Strict-Transport-Security.
public HeadersConfigurer contentSecurityPolicy(Customizer<HeadersConfigurer.ContentSecurityPolicyConfig> contentSecurityCustomizer)Content-Security-Policy; not sent unless configured here.
public HeadersConfigurer contentTypeOptions(Customizer<HeadersConfigurer.Toggle> contentTypeOptionsCustomizer)X-Content-Type-Options: nosniff.
public HeadersConfigurer xssProtection(Customizer<HeadersConfigurer.Toggle> xssCustomizer)X-XSS-Protection: 0, which tells an old browser to leave its faulty filter off.
public HeadersConfigurer cacheControl(Customizer<HeadersConfigurer.Toggle> cacheControlCustomizer)The headers that keep a response out of caches.
public HeadersConfigurer addHeaderWriter(HeaderWriter headerWriter)One more writer, run after the built-in ones.
public void configure(HttpSecurity http)Adds this part’s filters; nothing by default.

Inherited methods

Method details

defaultsDisabled

public HeadersConfigurer defaultsDisabled()
Turns every default off, leaving what is configured after this call.

frameOptions

public HeadersConfigurer frameOptions(Customizer<HeadersConfigurer.FrameOptionsConfig> frameOptionsCustomizer)
X-Frame-Options: whether a page may be shown in a frame.

httpStrictTransportSecurity

public HeadersConfigurer httpStrictTransportSecurity(Customizer<HeadersConfigurer.HstsConfig> hstsCustomizer)
Strict-Transport-Security.

contentSecurityPolicy

public HeadersConfigurer contentSecurityPolicy(Customizer<HeadersConfigurer.ContentSecurityPolicyConfig> contentSecurityCustomizer)
Content-Security-Policy; not sent unless configured here.

contentTypeOptions

public HeadersConfigurer contentTypeOptions(Customizer<HeadersConfigurer.Toggle> contentTypeOptionsCustomizer)
X-Content-Type-Options: nosniff.

xssProtection

public HeadersConfigurer xssProtection(Customizer<HeadersConfigurer.Toggle> xssCustomizer)
X-XSS-Protection: 0, which tells an old browser to leave its faulty filter off.

cacheControl

public HeadersConfigurer cacheControl(Customizer<HeadersConfigurer.Toggle> cacheControlCustomizer)
The headers that keep a response out of caches.

addHeaderWriter

public HeadersConfigurer addHeaderWriter(HeaderWriter headerWriter)
One more writer, run after the built-in ones.

configure

public void configure(HttpSecurity http)
Adds this part’s filters; nothing by default.