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

Extend support for various content encodings #144

Merged
merged 5 commits into from
Apr 18, 2021

Conversation

amitksingh1490
Copy link
Collaborator

No description provided.

@amitksingh1490 amitksingh1490 marked this pull request as draft April 15, 2021 11:17
@amitksingh1490 amitksingh1490 changed the title refactor(Http): HttpContent String to Byte[] refactor(Http): HttpContent Support various content encodings Apr 16, 2021
@amitksingh1490 amitksingh1490 changed the title refactor(Http): HttpContent Support various content encodings refactor(Http): HttpContent support various content encodings Apr 16, 2021
@amitksingh1490 amitksingh1490 linked an issue Apr 16, 2021 that may be closed by this pull request
@tusharmath tusharmath changed the title refactor(Http): HttpContent support various content encodings Extend support for various content encodings Apr 16, 2021
@amitksingh1490 amitksingh1490 marked this pull request as ready for review April 16, 2021 05:43

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]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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("")
Copy link
Collaborator

@tusharmath tusharmath Apr 17, 2021

Choose a reason for hiding this comment

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

Suggested change
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("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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))
Copy link
Collaborator

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.

@amitksingh1490 amitksingh1490 added enhancement New feature or request and removed bug Something isn't working labels Apr 17, 2021
@github-actions github-actions bot added the bug Something isn't working label Apr 17, 2021
@amitksingh1490 amitksingh1490 removed the bug Something isn't working label Apr 17, 2021
@github-actions github-actions bot added the bug Something isn't working label Apr 17, 2021
@amitksingh1490 amitksingh1490 removed the bug Something isn't working label Apr 17, 2021
@github-actions github-actions bot added the bug Something isn't working label Apr 18, 2021
@tusharmath tusharmath added automerge and removed bug Something isn't working labels Apr 18, 2021
@amitksingh1490 amitksingh1490 merged commit 842bf69 into main Apr 18, 2021
@amitksingh1490 amitksingh1490 deleted the fix/httpcontent-byte-array branch April 19, 2021 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support configurable request/response serialization
3 participants