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

Ember: Chunked Default like Blaze Semantics #3789

Merged
merged 2 commits into from Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 8 additions & 4 deletions ember-core/src/main/scala/org/http4s/ember/core/Encoder.scala
Expand Up @@ -16,10 +16,12 @@ private[ember] object Encoder {

private val SPACE = " "
private val CRLF = "\r\n"
val chunkedTansferEncodingHeaderRaw = "Transfer-Encoding: chunked"

def respToBytes[F[_]: Sync](
resp: Response[F],
writeBufferSize: Int = 32 * 1024): Stream[F, Byte] = {
val chunked = resp.isChunked
var chunked = resp.isChunked
val initSection = {
var appliedContentLength = false
val stringBuilder = new StringBuilder()
Expand All @@ -42,7 +44,8 @@ private[ember] object Encoder {
()
}
if (!chunked && !appliedContentLength) {
stringBuilder.append(`Content-Length`.zero.renderString).append(CRLF)
stringBuilder.append(chunkedTansferEncodingHeaderRaw).append(CRLF)
chunked = true
()
}
// Final CRLF terminates headers and signals body to follow.
Expand All @@ -59,7 +62,7 @@ private[ember] object Encoder {
}

def reqToBytes[F[_]: Sync](req: Request[F], writeBufferSize: Int = 32 * 1024): Stream[F, Byte] = {
val chunked = req.isChunked
var chunked = req.isChunked
val initSection = {
var appliedContentLength = false
val stringBuilder = new StringBuilder()
Expand Down Expand Up @@ -94,7 +97,8 @@ private[ember] object Encoder {
}

if (!chunked && !appliedContentLength) {
stringBuilder.append(`Content-Length`.zero.renderString).append(CRLF)
stringBuilder.append(chunkedTansferEncodingHeaderRaw).append(CRLF)
chunked = true
()
}

Expand Down
Expand Up @@ -40,7 +40,9 @@ class EncoderSpec extends Specification {
val expected =
"""GET http://www.google.com HTTP/1.1
|Host: www.google.com
|Content-Length: 0
|Transfer-Encoding: chunked
|
|0
|
|""".stripMargin

Expand Down Expand Up @@ -71,7 +73,9 @@ class EncoderSpec extends Specification {
"""GET http://www.google.com HTTP/1.1
|Host: www.google.com
|foo: bar
|Content-Length: 0
|Transfer-Encoding: chunked
|
|0
|
|""".stripMargin
Helpers.encodeRequestRig(req).unsafeRunSync() must_=== expected
Expand All @@ -84,7 +88,9 @@ class EncoderSpec extends Specification {

val expected =
"""HTTP/1.1 200 OK
|Content-Length: 0
|Transfer-Encoding: chunked
|
|0
|
|""".stripMargin

Expand Down