Skip to content

Commit fc5b6d9

Browse files
authored
Add missing required headers + update dependencies (#6755)
1 parent 0ff3ff9 commit fc5b6d9

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

frameworks/Scala/zio-http/build.sbt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
name := "zio-http"
2-
32
version := "1.0.0"
4-
scalaVersion := "2.13.3"
3+
scalaVersion := "2.13.6"
54
lazy val root = (project in file("."))
65
.settings(
7-
name := "helloExample",
86
libraryDependencies ++=
97
Seq(
10-
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.6.4",
11-
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.6.4" % "compile-internal",
12-
"io.d11" % "zhttp" % "1.0.0-RC3.1",
8+
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.9.1",
9+
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.9.1" % "compile-internal",
10+
"io.d11" % "zhttp" % "1.0.0-RC5",
1311
),
1412
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
1513
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 1.4.7
1+
sbt.version = 1.5.5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.0.0")

frameworks/Scala/zio-http/src/main/scala/Main.scala

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,40 @@ import zhttp.service.Server
33
import zio.{App, ExitCode, URIO}
44
import com.github.plokhotnyuk.jsoniter_scala.macros._
55
import com.github.plokhotnyuk.jsoniter_scala.core._
6-
import java.time.ZonedDateTime
6+
import zhttp.http.Response
7+
78
import java.time.format.DateTimeFormatter
9+
import java.time.{Instant, ZoneOffset}
10+
11+
case class Message(message: String)
812

9-
object WebApp extends App {
13+
object Main extends App {
1014
val message: String = "Hello, World!"
11-
def createDate: String = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now)
12-
case class Message(message: String)
1315
implicit val codec: JsonValueCodec[Message] = JsonCodecMaker.make
1416

15-
val app = Http.collect[Request] {
16-
case Method.GET -> Root / "plaintext" => Response.text(message)
17-
case Method.GET -> Root / "json" => Response.jsonString(writeToString(Message(message)))
17+
val app: Http[Any, HttpError, Request, Response] = Http.collect[Request] {
18+
case Method.GET -> Root / "plaintext" =>
19+
Response.http(
20+
content = HttpContent.Complete(message),
21+
headers = Header.contentTypeTextPlain :: headers(),
22+
)
23+
case Method.GET -> Root / "json" =>
24+
Response.http(
25+
content = HttpContent.Complete(writeToString(Message(message))),
26+
headers = Header.contentTypeJson :: headers(),
27+
)
1828
}
1929

2030
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = Server.start(8080, app).exitCode
2131

32+
val formatter: DateTimeFormatter = DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneOffset.UTC)
33+
val constantHeaders: List[Header] = Header("server", "zio-http") :: Nil
34+
@volatile var lastHeaders: (Long, List[Header]) = (0, Nil)
35+
36+
def headers(): List[Header] = {
37+
val t = System.currentTimeMillis()
38+
if (t - lastHeaders._1 >= 1000)
39+
lastHeaders = (t, Header("date", formatter.format(Instant.ofEpochMilli(t))) :: constantHeaders)
40+
lastHeaders._2
41+
}
2242
}

frameworks/Scala/zio-http/zio-http.dockerfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
FROM openjdk:11-jdk
22

3-
ARG SBT_VERSION=1.2.8
4-
53
RUN \
6-
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
7-
dpkg -i sbt-$SBT_VERSION.deb && \
8-
rm sbt-$SBT_VERSION.deb && \
4+
echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | tee /etc/apt/sources.list.d/sbt.list && \
5+
echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | tee /etc/apt/sources.list.d/sbt_old.list && \
6+
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | apt-key add && \
97
apt-get update && \
10-
apt-get install sbt && \
11-
sbt sbtVersion
8+
apt-get install sbt
129

1310
WORKDIR /zhttp
1411
COPY src src

0 commit comments

Comments
 (0)