HttpServerSettings.kt

  1. package com.hexagonkt.http.server

  2. import com.hexagonkt.core.Jvm
  3. import com.hexagonkt.core.urlOf
  4. import com.hexagonkt.http.SslSettings
  5. import com.hexagonkt.http.model.HttpProtocol
  6. import com.hexagonkt.http.model.HttpProtocol.HTTP
  7. import java.net.InetAddress
  8. import java.net.URL

  9. /**
  10.  * Holds server settings info.
  11.  *
  12.  * @property bindAddress Address for the server.
  13.  * @property bindPort Port for the server.
  14.  * @property contextPath Context Path for the server's incoming requests.
  15.  * @property protocol Server's protocol.
  16.  * @property sslSettings SSL settings info for configuring the server.
  17.  * @property banner Server banner message.
  18.  * @property zip Option to compress server responses.
  19.  * @property bindUrl Base URL to connect to the server. It lacks the port (as it can be dynamic).
  20.  */
  21. data class HttpServerSettings(
  22.     val bindAddress: InetAddress = InetAddress.getLoopbackAddress(),
  23.     val bindPort: Int = 2010,
  24.     val contextPath: String = "",
  25.     val protocol: HttpProtocol = HTTP,
  26.     val sslSettings: SslSettings? = null,
  27.     val banner: String? = HttpServer.banner,
  28.     val zip: Boolean = false,
  29. ) {
  30.     val bindUrl: URL by lazy {
  31.         val hostName = if (bindAddress.isAnyLocalAddress) Jvm.ip else bindAddress.canonicalHostName
  32.         val scheme = if (protocol == HTTP) "http" else "https"
  33.         urlOf("$scheme://$hostName")
  34.     }
  35. }