Package io.muserver.handlers
Class HttpsRedirectorBuilder
- java.lang.Object
-
- io.muserver.handlers.HttpsRedirectorBuilder
-
- All Implemented Interfaces:
MuHandlerBuilder<HttpsRedirector>
- Direct Known Subclasses:
HttpsRedirector.Builder
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 HttpsRedirector
build()
HttpsRedirectorBuilder
includeSubDomains(boolean includeSubDomainsForHSTS)
Specifies that any subdomains should have HSTS enforced too.static HttpsRedirectorBuilder
toHttpsPort(int port)
Creates a new redirect builderHttpsRedirectorBuilder
withHSTSExpireTime(int expireTime, java.util.concurrent.TimeUnit unit)
If set to a positive number, this will add aStrict-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 example443
-
-
-
Method Detail
-
build
public HttpsRedirector build()
- Specified by:
build
in 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
-true
to include the preload directive;false
to 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-Security
header 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
-true
to include theincludeSubDomains
directive in theStrict-Transport-Security
header 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
-
-