|
@@ -1,4 +1,6 @@
|
|
|
import java.net.InetSocketAddress
|
|
|
+import java.text.{DateFormat, SimpleDateFormat}
|
|
|
+import java.util.Date
|
|
|
|
|
|
import io.finch._
|
|
|
|
|
@@ -14,18 +16,24 @@ import io.circe.syntax._
|
|
|
import io.circe.{Decoder, Encoder, Json}
|
|
|
|
|
|
object WebServer extends App {
|
|
|
+ private val dateFormat: DateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z")
|
|
|
|
|
|
import io.finch.circe._
|
|
|
val json = get("json") {
|
|
|
Ok(Json.obj("message" -> Json.string("Hello, World!")))
|
|
|
+ .withHeader("Server" -> "finch")
|
|
|
+ .withHeader("Date" -> dateFormat.format(new Date()))
|
|
|
}
|
|
|
|
|
|
val plaintext: Endpoint[String] = get("plaintext") {
|
|
|
Ok("Hello, World!")
|
|
|
+ .withHeader("Server" -> "finch")
|
|
|
+ .withHeader("Date" -> dateFormat.format(new Date()))
|
|
|
.withContentType(Some("text/plain"))
|
|
|
}
|
|
|
|
|
|
- Await.ready(
|
|
|
- Http.serve(":9000", (json :+: plaintext).toService)
|
|
|
+ Await.ready(Http.server
|
|
|
+ .withCompressionLevel(0)
|
|
|
+ .serve(":9000", (json :+: plaintext).toService)
|
|
|
)
|
|
|
}
|