Package io.muserver.handlers
Class HttpsRedirectorBuilder
- java.lang.Object
-
- io.muserver.handlers.HttpsRedirectorBuilder
-
- All Implemented Interfaces:
MuHandlerBuilder<HttpsRedirector>
public class HttpsRedirectorBuilder extends java.lang.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 Summary
Constructors Constructor Description HttpsRedirectorBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpsRedirectorbuild()HttpsRedirectorBuilderincludeSubDomains(boolean includeSubDomainsForHSTS)Specifies that any subdomains should have HSTS enforced too.static HttpsRedirectorBuildertoHttpsPort(int port)Creates a new redirect builderHttpsRedirectorBuilderwithHSTSExpireTime(int expireTime, java.util.concurrent.TimeUnit unit)If set to a positive number, this will add aStrict-Transport-Securityheader to all HTTPS responses to indicate that clients should always use HTTPS to access this server.HttpsRedirectorBuilderwithHSTSPreload(boolean preload)Specifies that this website can be added to the HSTS preload lists.HttpsRedirectorBuilderwithPort(int port)Sets the port to redirect HTTP requests to, for example443
-
-
-
Method Detail
-
build
public HttpsRedirector build()
- Specified by:
buildin interfaceMuHandlerBuilder<HttpsRedirector>- Returns:
- A newly built
MuHandler
-
withPort
public HttpsRedirectorBuilder withPort(int port)
Sets the port to redirect HTTP requests to, for example443- Parameters:
port- The port that the HTTPS version of this website is available at.- Returns:
- Returns this builder.
-
withHSTSPreload
public HttpsRedirectorBuilder withHSTSPreload(boolean preload)
Specifies that this website can be added to the HSTS preload lists. See https://hstspreload.org/ for more info.
- Parameters:
preload-trueto include the preload directive;falseto not.- Returns:
- Returns this builder.
-
withHSTSExpireTime
public HttpsRedirectorBuilder withHSTSExpireTime(int expireTime, java.util.concurrent.TimeUnit unit)
If set to a positive number, this will add a
Strict-Transport-Securityheader to all HTTPS responses to indicate that clients should always use HTTPS to access this server.This is not enabled by default.
- Parameters:
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.- Returns:
- Returns this builder.
-
includeSubDomains
public HttpsRedirectorBuilder includeSubDomains(boolean includeSubDomainsForHSTS)
Specifies that any subdomains should have HSTS enforced too.
- Parameters:
includeSubDomainsForHSTS-trueto include theincludeSubDomainsdirective in theStrict-Transport-Securityheader value.- Returns:
- Returns this builder.
-
toHttpsPort
public static HttpsRedirectorBuilder toHttpsPort(int port)
Creates a new redirect builder- Parameters:
port- The port to redirect to (e.g. 443)- Returns:
- A new builder
-
-