Skip to content

Commit

Permalink
Handle http/2 request body without content-length
Browse files Browse the repository at this point in the history
Http/2 is always streaming, so setting content-length is optional.
  • Loading branch information
hamnis committed Dec 7, 2024
1 parent 3c8067a commit 8637741
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ object JdkHttpClient {
def convertRequest(req: Request[F]): Resource[F, HttpRequest] =
flow.toPublisher(req.body.chunks.map(_.toByteBuffer)).evalMap { publisher =>
convertHttpVersionFromHttp4s[F](req.httpVersion).map { version =>
def isStreaming = version match {
case HttpClient.Version.HTTP_1_1 => req.isChunked
case HttpClient.Version.HTTP_2 => req.contentLength.isEmpty
}

val rb = HttpRequest.newBuilder
.method(
req.method.name,
if (req.isChunked)
if (isStreaming)
BodyPublishers.fromPublisher(publisher)
else
req.contentLength match {
Expand Down

0 comments on commit 8637741

Please sign in to comment.