Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(domain): add default headers in Response #37

Merged
merged 6 commits into from
Mar 16, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion zio-http/src/main/scala/zhttp/http/Response.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import zio.Task
import zio.stream.ZStream

import java.io.{PrintWriter, StringWriter}
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

// RESPONSE
sealed trait Response extends Product with Serializable { self => }
Expand All @@ -34,6 +36,8 @@ object Response {
val jContentBytBuf = res.content match {
case HttpContent.Complete(data) =>
jHttpHeaders.set(JHttpHeaderNames.CONTENT_LENGTH, data.length())
jHttpHeaders.set(JHttpHeaderNames.SERVER, "zio-http")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zio-http can be moved up so that the string is allocated only once.

jHttpHeaders.set(JHttpHeaderNames.DATE, s"${DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now)}")
JUnpooled.copiedBuffer(data, HTTP_CHARSET)

case _ =>
Expand Down Expand Up @@ -97,7 +101,6 @@ object Response {
def jsonString(data: String): Response =
http(
content = HttpContent.Complete(data),
headers = List(Header.contentTypeJson),
)

def status(status: Status): Response = http(status)
Expand Down