Class HttpsRedirectorBuilder

  • All Implemented Interfaces:

    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()
                     .addHandler(HttpsRedirectorBuilder.toHttpsPort(443).withHSTSExpireTime(365, TimeUnit.DAYS))
                     .addHandler( ... your handler ... )
    • Constructor Detail

      • HttpsRedirectorBuilder

        public HttpsRedirectorBuilder()
    • Method Detail

      • withPort

        public HttpsRedirectorBuilder withPort​(int port)
        Sets the port to redirect HTTP requests to, for example 443
        port - The port that the HTTPS version of this website is available at.
        Returns this builder.
      • withHSTSPreload

        public HttpsRedirectorBuilder withHSTSPreload​(boolean preload)

        Specifies that this website can be added to the HSTS preload lists. See for more info.

        preload - true to include the preload directive; false to not.
        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.

        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 this builder.
      • includeSubDomains

        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.
        Returns this builder.
      • toHttpsPort

        public static HttpsRedirectorBuilder toHttpsPort​(int port)
        Creates a new redirect builder
        port - The port to redirect to (e.g. 443)
        A new builder