Browse Source

No gzip. Date and Server headers added.

mfirry 9 years ago
parent
commit
a01f76830d
1 changed files with 10 additions and 2 deletions
  1. 10 2
      frameworks/Scala/finch/src/main/scala/WebServer.scala

+ 10 - 2
frameworks/Scala/finch/src/main/scala/WebServer.scala

@@ -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)
   )
 }