Class 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 Detail

      • HttpsRedirectorBuilder

        public HttpsRedirectorBuilder()
    • Method Detail

      • withPort

        public HttpsRedirectorBuilder withPort​(int port)
        Sets the port to redirect HTTP requests to, for example 443
        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 the includeSubDomains directive in the Strict-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