public class HttpsRedirectorBuilder extends Object implements MuHandlerBuilder<HttpsRedirector>
A builder for a handler that sends any HTTP requests to the same HTTPS address at the supplied port and optionally enables Strict-Transport-Security (HSTS)
Sample usage:
server = MuServerBuilder.muServer() .withHttpPort(80) .withHttpsPort(443) .addHandler(HttpsRedirectorBuilder.toHttpsPort(443).withHSTSExpireTime(365, TimeUnit.DAYS)) .addHandler( ... your handler ... ) .start();
Constructor and Description |
---|
HttpsRedirectorBuilder() |
Modifier and Type | Method and Description |
---|---|
HttpsRedirector |
build() |
HttpsRedirectorBuilder |
includeSubDomains(boolean includeSubDomainsForHSTS)
Specifies that any subdomains should have HSTS enforced too.
|
static HttpsRedirectorBuilder |
toHttpsPort(int port)
Creates a new redirect builder
|
HttpsRedirectorBuilder |
withHSTSExpireTime(int expireTime,
TimeUnit unit)
If set to a positive number, this will add a
Strict-Transport-Security header to all HTTPS
responses to indicate that clients should always use HTTPS to access this server. |
HttpsRedirectorBuilder |
withHSTSPreload(boolean preload)
Specifies that this website can be added to the HSTS preload lists.
|
HttpsRedirectorBuilder |
withPort(int port)
Sets the port to redirect HTTP requests to, for example
443 |
public HttpsRedirector build()
build
in interface MuHandlerBuilder<HttpsRedirector>
MuHandler
public HttpsRedirectorBuilder withPort(int port)
443
port
- The port that the HTTPS version of this website is available at.public HttpsRedirectorBuilder withHSTSPreload(boolean preload)
Specifies that this website can be added to the HSTS preload lists. See https://hstspreload.org/ for more info.
preload
- true
to include the preload directive; false
to not.public HttpsRedirectorBuilder withHSTSExpireTime(int expireTime, TimeUnit unit)
If set to a positive number, this will add a Strict-Transport-Security
header to all HTTPS
responses to indicate that clients should always use HTTPS to access this server.
This is not enabled by default.
expireTime
- The time that the browser should remember that a site is only to be accessed using HTTPS.unit
- The unit of the expiry time.public HttpsRedirectorBuilder includeSubDomains(boolean includeSubDomainsForHSTS)
Specifies that any subdomains should have HSTS enforced too.
includeSubDomainsForHSTS
- true
to include the includeSubDomains
directive in the Strict-Transport-Security
header value.public static HttpsRedirectorBuilder toHttpsPort(int port)
port
- The port to redirect to (e.g. 443)Copyright © 2017–2021. All rights reserved.