-
Notifications
You must be signed in to change notification settings - Fork 383
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
Extend support for various content encodings #144
Conversation
|
||
object HttpContent { | ||
final case class Complete[A](data: A) extends HttpContent[Any, A] | ||
final case class Chunked[R, A](data: ZStream[R, Nothing, A]) extends HttpContent[R, A] | ||
final case class StringEncoded(string: String) extends HttpContent[Any, Nothing] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final case class StringEncoded(string: String) extends HttpContent[Any, Nothing] | |
final case object Empty extends HttpContent[Any, Nothing] | |
final case class StringEncoded(string: String) | |
extends HttpContent[Any, Nothing] |
} | ||
|
||
object Request { | ||
val emptyContent: HttpContent.Complete[String] = HttpContent.Complete("") | ||
final case class Data(headers: List[Header], content: HttpContent[Any, String]) | ||
val emptyContent: HttpContent.StringEncoded = HttpContent.StringEncoded("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val emptyContent: HttpContent.StringEncoded = HttpContent.StringEncoded("") | |
val emptyContent: HttpContent[Any, Nothing]= HttpContent.empty |
|
||
import java.io.{PrintWriter, StringWriter} | ||
|
||
trait ResponseOps { | ||
private val defaultStatus = Status.OK | ||
private val defaultHeaders = Nil | ||
private val emptyContent = HttpContent.Complete("") | ||
private val emptyContent = HttpContent.StringEncoded("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private val emptyContent = HttpContent.StringEncoded("") | |
private val emptyContent = HttpContent.empty |
final case class StringEncoded(string: String) extends HttpContent[Any, Nothing] | ||
final case class ByteEncoded(data: Chunk[Byte]) extends HttpContent[Any, Nothing] | ||
final case class ByteBufEncoded(byteBuf: ByteBuf) extends HttpContent[Any, Nothing] | ||
final case class ByteBufEncodedM[R, E](byteBuf: ZIO[R, E, ByteBuf]) extends HttpContent[R, E] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final case class ByteBufEncodedM[R, E](byteBuf: ZIO[R, E, ByteBuf]) extends HttpContent[R, E] |
status: Status = defaultStatus, | ||
headers: List[Header] = defaultHeaders, | ||
content: HttpContent[R, String] = emptyContent, | ||
): Response.HttpResponse[R] = | ||
content: HttpContent[R, Nothing] = emptyContent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content: HttpContent[R, Nothing] = emptyContent, | |
content: HttpContent[R, E] = emptyContent, |
case _ => Option.empty | ||
case HttpContent.StringEncoded(string) => Option(string) | ||
case HttpContent.ByteEncoded(data) => Option(data.map(_.toChar).mkString) | ||
case HttpContent.ByteBufEncoded(byteBuf) => Option(byteBuf.toString(HTTP_CHARSET)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
byteBuf.toString
is an effectful function.
fb6ccaa
to
cc1b8c8
Compare
5a749d7
to
5ea68d5
Compare
No description provided.