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

Merge series/0.23 into main #926

Merged
merged 116 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
439a097
Update scala-library to 2.13.12 in series/0.23
http4s-steward[bot] Sep 11, 2023
dd36409
Update sbt-http4s-org to 0.15.2 in series/0.23
http4s-steward[bot] Sep 12, 2023
3810ff5
Run prePR with sbt-typelevel
http4s-steward[bot] Sep 12, 2023
7409308
Merge pull request #831 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Sep 13, 2023
2dbcd87
Merge branch 'series/0.23' into update/series/0.23/scala-library-2.13.12
mergify[bot] Sep 13, 2023
a12b9ab
Merge pull request #830 from http4s/update/series/0.23/scala-library-…
danicheg Sep 13, 2023
70d9e6a
Update sbt to 1.9.6 in series/0.23
http4s-steward[bot] Sep 15, 2023
dcc84d8
Update sbt-http4s-org to 0.15.3 in series/0.23
http4s-steward[bot] Sep 16, 2023
5c4f4e8
Merge pull request #833 from http4s/update/series/0.23/sbt-1.9.6
danicheg Sep 17, 2023
b7434e9
Merge pull request #834 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Sep 18, 2023
6a7dda3
Update sbt-http4s-org to 0.16.0 in series/0.23
http4s-steward[bot] Oct 18, 2023
d584e62
Run prePR with sbt-typelevel
http4s-steward[bot] Oct 18, 2023
1c99ba5
Merge pull request #836 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Oct 19, 2023
d0df90c
Update sbt to 1.9.7 in series/0.23
http4s-steward[bot] Oct 23, 2023
1b41abc
Merge pull request #837 from http4s/update/series/0.23/sbt-1.9.7
danicheg Oct 24, 2023
a96482e
Update munit-cats-effect to 2.0.0-M4 in series/0.23
http4s-steward[bot] Nov 13, 2023
66d5849
Update sbt-http4s-org to 0.16.1 in series/0.23
http4s-steward[bot] Nov 13, 2023
77c2f8e
Merge pull request #838 from http4s/update/series/0.23/munit-cats-eff…
danicheg Nov 14, 2023
fa45ad3
Update http4s-circe, http4s-client, ... to 0.23.24 in series/0.23
http4s-steward[bot] Nov 14, 2023
a7958af
Merge pull request #840 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Nov 15, 2023
304f0f6
Merge pull request #841 from http4s/update/series/0.23/http4s-core-0.…
danicheg Nov 16, 2023
4aee409
Update logback-classic to 1.2.13 in series/0.23
http4s-steward[bot] Dec 1, 2023
e6f4bec
Merge pull request #842 from http4s/update/series/0.23/logback-classi…
danicheg Dec 2, 2023
6965416
Update sbt-http4s-org to 0.16.2 in series/0.23
http4s-steward[bot] Dec 3, 2023
5afdf08
Run prePR with sbt-typelevel
http4s-steward[bot] Dec 3, 2023
f459390
Merge pull request #843 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Dec 4, 2023
6d9a4ef
Update sbt to 1.9.8 in series/0.23
http4s-steward[bot] Dec 14, 2023
f3777c1
Merge pull request #844 from http4s/update/series/0.23/sbt-1.9.8
danicheg Dec 15, 2023
324181e
Update http4s-circe, http4s-client, ... to 0.23.25 in series/0.23
http4s-steward[bot] Jan 3, 2024
667b2bc
Merge pull request #848 from http4s/update/series/0.23/http4s-core-0.…
rossabaker Jan 4, 2024
a26696a
Update sbt to 1.9.9 in series/0.23
http4s-steward[bot] Feb 23, 2024
0aef1e4
Merge pull request #850 from http4s/update/series/0.23/sbt-1.9.9
rossabaker Feb 23, 2024
9e49ba9
Update kind-projector to 0.13.3 in series/0.23
http4s-steward[bot] Feb 24, 2024
904d118
Merge pull request #851 from http4s/update/series/0.23/kind-projector…
danicheg Feb 25, 2024
0adc5b9
Update scala-library to 2.12.19 in series/0.23
http4s-steward[bot] Feb 27, 2024
4eb72df
Update scala-library to 2.13.13 in series/0.23
http4s-steward[bot] Feb 27, 2024
cf9f5cf
Update sbt-http4s-org to 0.16.3 in series/0.23
http4s-steward[bot] Feb 27, 2024
bf16a43
Run prePR with sbt-typelevel
http4s-steward[bot] Feb 27, 2024
76af0c5
Update scala3-library to 3.3.3 in series/0.23
http4s-steward[bot] Feb 29, 2024
59ffe72
Merge pull request #853 from http4s/update/series/0.23/scala-library-…
danicheg Mar 1, 2024
07d6a03
Merge pull request #855 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Mar 1, 2024
13038fc
Merge branch 'series/0.23' into update/series/0.23/scala-library-2.13.13
danicheg Mar 1, 2024
97de40e
Fix compilation for Scala 2.13.13
danicheg Mar 1, 2024
45bc637
Merge pull request #856 from http4s/update/series/0.23/scala3-library…
danicheg Mar 4, 2024
a6d87b9
Merge branch 'series/0.23' into update/series/0.23/scala-library-2.13.13
danicheg Mar 4, 2024
2099ddc
Update http4s-circe, http4s-client, ... to 0.23.26 in series/0.23
http4s-steward[bot] Mar 5, 2024
cbe0407
Merge pull request #859 from http4s/update/series/0.23/http4s-core-0.…
rossabaker Mar 5, 2024
321f812
Merge pull request #854 from http4s/update/series/0.23/scala-library-…
rossabaker Mar 12, 2024
557fc92
Update sbt-buildinfo to 0.12.0 in series/0.23
http4s-steward[bot] Mar 20, 2024
1f0427e
Merge pull request #862 from http4s/update/series/0.23/sbt-buildinfo-…
danicheg Mar 20, 2024
61ea14e
Update munit-cats-effect to 2.0.0-M5 in series/0.23
http4s-steward[bot] Apr 13, 2024
3bd449c
Merge pull request #865 from http4s/update/series/0.23/munit-cats-eff…
danicheg Apr 13, 2024
4aeab7d
Update sbt-http4s-org to 0.17.0 in series/0.23
http4s-steward[bot] Apr 25, 2024
cd75581
Fix Scalafix
danicheg Apr 26, 2024
f0ff468
Merge pull request #867 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Apr 26, 2024
8a92263
Update circe-generic to 0.14.7 in series/0.23
http4s-steward[bot] Apr 26, 2024
b4fce28
Merge pull request #868 from http4s/update/series/0.23/circe-generic-…
danicheg May 1, 2024
4f825b1
Update scala-library to 2.13.14 in series/0.23
http4s-steward[bot] May 2, 2024
328943a
Update http4s-circe, http4s-client, ... to 0.23.27 in series/0.23
http4s-steward[bot] May 3, 2024
3f4db31
Merge pull request #869 from http4s/update/series/0.23/scala-library-…
danicheg May 4, 2024
78b8f3b
Merge pull request #871 from http4s/update/series/0.23/http4s-core-0.…
danicheg May 5, 2024
c8e5e68
Update sbt to 1.10.0 in series/0.23
http4s-steward[bot] May 6, 2024
4ad3ae9
Update munit-cats-effect to 2.0.0-RC1 in series/0.23
http4s-steward[bot] May 8, 2024
51ac92d
Merge pull request #872 from http4s/update/series/0.23/sbt-1.10.0
danicheg May 8, 2024
28ff87d
Update sbt-http4s-org to 0.17.1 in series/0.23
http4s-steward[bot] May 9, 2024
dab1fc3
Merge pull request #873 from http4s/update/series/0.23/munit-cats-eff…
danicheg May 10, 2024
ba20dc0
Merge pull request #875 from http4s/update/series/0.23/sbt-http4s-org…
rossabaker May 10, 2024
6d6e2c5
Update munit-cats-effect to 2.0.0 in series/0.23
http4s-steward[bot] May 23, 2024
4ec7351
Merge pull request #877 from http4s/update/series/0.23/munit-cats-eff…
rossabaker May 24, 2024
a583315
Update circe-generic to 0.14.8 in series/0.23
http4s-steward[bot] Jun 18, 2024
729bf12
Merge pull request #882 from http4s/update/series/0.23/circe-generic-…
danicheg Jun 18, 2024
a7e3fe0
Update circe-generic to 0.14.9 in series/0.23
http4s-steward[bot] Jul 1, 2024
9ccd240
Merge pull request #884 from http4s/update/series/0.23/circe-generic-…
rossabaker Jul 5, 2024
294295f
Update sbt to 1.10.1 in series/0.23
http4s-steward[bot] Jul 8, 2024
d7b6597
Merge pull request #886 from http4s/update/series/0.23/sbt-1.10.1
rossabaker Jul 8, 2024
8f2c9bb
Update sbt-http4s-org to 0.17.2 in series/0.23
http4s-steward[bot] Jul 29, 2024
03aea59
Run prePR with sbt-typelevel
http4s-steward[bot] Jul 29, 2024
73c2a34
Merge pull request #888 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Jul 29, 2024
d8dd1c2
Update async-http-client to 3.0.0 in series/0.23
http4s-steward[bot] Jul 30, 2024
34bba20
Update circe-generic to 0.14.10 in series/0.23
http4s-steward[bot] Sep 8, 2024
fda9c02
Update sbt-http4s-org to 0.17.3 in series/0.23
http4s-steward[bot] Sep 8, 2024
ea15d48
Run prePR with sbt-typelevel
http4s-steward[bot] Sep 8, 2024
7d6a37e
Update scala-library to 2.12.20 in series/0.23
http4s-steward[bot] Sep 8, 2024
4420583
Merge pull request #899 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Sep 9, 2024
6040d68
Merge pull request #898 from http4s/update/series/0.23/circe-generic-…
danicheg Sep 9, 2024
6315ca5
Merge branch 'series/0.23' into update/series/0.23/scala-library-2.12.20
mergify[bot] Sep 9, 2024
4821569
Merge pull request #900 from http4s/update/series/0.23/scala-library-…
danicheg Sep 9, 2024
7cd6e27
Update http4s-circe, http4s-client, ... to 0.23.28 in series/0.23
http4s-steward[bot] Sep 10, 2024
2d23d71
Merge pull request #901 from http4s/update/series/0.23/http4s-core-0.…
danicheg Sep 10, 2024
be4c3d4
Update sbt to 1.10.2 in series/0.23
http4s-steward[bot] Sep 16, 2024
d679de9
Merge pull request #902 from http4s/update/series/0.23/sbt-1.10.2
danicheg Sep 16, 2024
995e826
Update scala-library to 2.13.15 in series/0.23
http4s-steward[bot] Sep 25, 2024
7058a6d
Merge pull request #904 from http4s/update/series/0.23/scala-library-…
danicheg Sep 28, 2024
3ca1332
Update scala3-library to 3.3.4 in series/0.23
http4s-steward[bot] Sep 28, 2024
d3a1282
Merge pull request #905 from http4s/update/series/0.23/scala3-library…
danicheg Sep 29, 2024
ff6f913
Merge pull request #889 from http4s/update/series/0.23/async-http-cli…
rossabaker Oct 16, 2024
38b6658
Update sbt to 1.10.3 in series/0.23
http4s-steward[bot] Oct 20, 2024
5dedf9e
Merge pull request #910 from http4s/update/series/0.23/sbt-1.10.3
danicheg Oct 21, 2024
cbd39ce
Update http4s-circe, http4s-client, ... to 0.23.29 in series/0.23
http4s-steward[bot] Oct 23, 2024
6a09fd1
Merge pull request #911 from http4s/update/series/0.23/http4s-core-0.…
rossabaker Oct 23, 2024
f49d016
Update sbt-http4s-org to 0.17.5 in series/0.23
http4s-steward[bot] Oct 24, 2024
c9b84fc
Run prePR with sbt-typelevel
http4s-steward[bot] Oct 24, 2024
09c9c18
Merge pull request #912 from http4s/update/series/0.23/sbt-http4s-org…
danicheg Oct 24, 2024
78f2e24
Update sbt to 1.10.4 in series/0.23
http4s-steward[bot] Oct 28, 2024
a89d35d
Merge pull request #914 from http4s/update/series/0.23/sbt-1.10.4
rossabaker Oct 28, 2024
a6581f3
Fix Connection persistence according to RFC 9112
rossabaker Nov 2, 2024
c1a214f
Update sbt-buildinfo to 0.13.0 in series/0.23
http4s-steward[bot] Nov 3, 2024
13a7a35
Merge pull request #919 from http4s/update/series/0.23/sbt-buildinfo-…
rossabaker Nov 3, 2024
db73e98
Update sbt to 1.10.5 in series/0.23
http4s-steward[bot] Nov 4, 2024
6579d53
Merge pull request #921 from http4s/update/series/0.23/sbt-1.10.5
danicheg Nov 4, 2024
17766b8
Merge pull request #917 from http4s/connection-closing-0.23
rossabaker Nov 4, 2024
5c20509
Update sbt-buildinfo to 0.13.1 in series/0.23
http4s-steward[bot] Nov 9, 2024
f5cbe39
Merge pull request #924 from http4s/update/series/0.23/sbt-buildinfo-…
danicheg Nov 10, 2024
d1caed9
Merge branch 'series/0.23' into main
danicheg Nov 17, 2024
55126f4
Fix Http1ServerStageSpec
danicheg Nov 17, 2024
e5ee8ba
Update http4s-core to 1.0.0-M44
danicheg Dec 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- name: Install sbt
uses: sbt/setup-sbt@v1

- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
id: setup-java-temurin-8
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
Expand Down Expand Up @@ -91,7 +94,7 @@ jobs:

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar
Expand All @@ -106,15 +109,18 @@ jobs:
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
uses: sbt/setup-sbt@v1

- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
id: setup-java-temurin-8
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
Expand All @@ -125,7 +131,7 @@ jobs:
run: sbt +update

- name: Download target directories (3)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3

Expand All @@ -135,7 +141,7 @@ jobs:
rm targets.tar

- name: Download target directories (2.13)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13

Expand All @@ -149,15 +155,15 @@ jobs:
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
run: echo $PGP_SECRET | base64 -di | gpg --import
run: echo $PGP_SECRET | base64 -d -i - | gpg --import

- name: Import signing key and strip passphrase
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE != ''
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
run: |
echo "$PGP_SECRET" | base64 -di > /tmp/signing-key.gpg
echo "$PGP_SECRET" | base64 -d -i - > /tmp/signing-key.gpg
echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg
(echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)

Expand All @@ -170,22 +176,25 @@ jobs:

dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
if: github.event.repository.fork == false && github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
uses: sbt/setup-sbt@v1

- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
id: setup-java-temurin-8
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
Expand All @@ -210,12 +219,12 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (fast)
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.http4s.Uri.RegName
import org.http4s.blaze.core.Http1Stage
import org.http4s.blaze.core.IdleTimeoutStage
import org.http4s.blaze.core.util.Http1Writer
import org.http4s.blaze.core.util.NullWriter
import org.http4s.blaze.pipeline.Command.EOF
import org.http4s.client.RequestKey
import org.http4s.headers.Host
Expand Down Expand Up @@ -200,10 +201,8 @@ private final class Http1Connection[F[_]](
if (userAgent.nonEmpty && !req.headers.contains[`User-Agent`])
rr << userAgent.get << "\r\n"

val mustClose: Boolean = req.headers.get[HConnection] match {
case Some(conn) => checkCloseConnection(conn, rr)
case None => getHttpMinor(req) == 0
}
val mustClose: Boolean =
checkRequestCloseConnection(req.headers.get[HConnection], getHttpMinor(req), NullWriter)

val writeRequest: F[Boolean] = getChunkEncoder(req, mustClose, rr)
.write(rr, req.entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package client
import cats.effect._
import cats.effect.kernel.Resource
import cats.effect.std.Dispatcher
import cats.implicits.catsSyntaxApplicativeId
import cats.syntax.all._
import fs2.Stream
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -141,9 +140,9 @@ trait BlazeClientBase extends CatsEffectSuite {
)

val server: IOFixture[ServerScaffold[IO]] =
ResourceSuiteLocalFixture("http", makeScaffold(2, false))
ResourceSuiteLocalFixture("http", makeScaffold(2, secure = false))
val secureServer: IOFixture[ServerScaffold[IO]] =
ResourceSuiteLocalFixture("https", makeScaffold(1, true))
ResourceSuiteLocalFixture("https", makeScaffold(1, secure = true))

override val munitFixtures = List(
server,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class BlazeClientSuite extends BlazeClientBase {
}
override def onRequestEnd(ctx: ChannelHandlerContext, request: HttpRequest): Unit = ()
})
ServerScaffold[IO](1, false, HandlersToNettyAdapter[IO](handlers)).use { server =>
ServerScaffold[IO](1, secure = false, HandlersToNettyAdapter[IO](handlers)).use { server =>
val address = server.addresses.head
val name = address.host
val port = address.port
Expand All @@ -343,7 +343,7 @@ class BlazeClientSuite extends BlazeClientBase {
}
override def onRequestEnd(ctx: ChannelHandlerContext, request: HttpRequest): Unit = ()
})
ServerScaffold[IO](1, false, HandlersToNettyAdapter[IO](handlers)).use { server =>
ServerScaffold[IO](1, secure = false, HandlersToNettyAdapter[IO](handlers)).use { server =>
val address = server.addresses.head
val name = address.host
val port = address.port
Expand All @@ -366,7 +366,7 @@ class BlazeClientSuite extends BlazeClientBase {
}
override def onRequestEnd(ctx: ChannelHandlerContext, request: HttpRequest): Unit = ()
})
ServerScaffold[IO](1, false, HandlersToNettyAdapter[IO](handlers)).use { server =>
ServerScaffold[IO](1, secure = false, HandlersToNettyAdapter[IO](handlers)).use { server =>
val address = server.addresses.head
val name = address.host
val port = address.port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import cats.effect._
import cats.effect.kernel.Deferred
import cats.effect.std.Dispatcher
import cats.effect.std.Queue
import cats.syntax.all._
import fs2.Stream
import munit.CatsEffectSuite
import org.http4s.BuildInfo
Expand Down
37 changes: 37 additions & 0 deletions blaze-core/src/main/scala/org/http4s/blaze/core/Http1Stage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private[blaze] trait Http1Stage[F[_]] { self: TailStage[ByteBuffer] =>
protected def contentComplete(): Boolean

/** Check Connection header and add applicable headers to response */
@deprecated("Use checkConnectionPersistence(Option[Connection], Int, Writer) instead", "0.23.17")
protected final def checkCloseConnection(conn: Connection, rr: StringWriter): Boolean =
if (conn.hasKeepAlive) { // connection, look to the request
logger.trace("Found Keep-Alive header")
Expand All @@ -83,6 +84,42 @@ private[blaze] trait Http1Stage[F[_]] { self: TailStage[ByteBuffer] =>
true
}

/** Checks whether the connection should be closed per the request's Connection header
* and the HTTP version.
*
* As a side effect, writes a "Connection: close" header to the StringWriter if
* the request explicitly requests the connection is closed.
*
* @see [[https://datatracker.ietf.org/doc/html/rfc9112#name-persistence RFC 9112, Section 9.3, Persistence]]
*/
private[http4s] final def checkRequestCloseConnection(
conn: Option[Connection],
minorVersion: Int,
rr: Writer,
): Boolean =
if (conn.fold(false)(_.hasClose)) {
logger.trace(s"Closing ${conn} due to explicit close option in request's Connection header")
// This side effect doesn't really belong here, but is relied
// upon in multiple places as we look for the encoder. The
// related problem of writing the keep-alive header in HTTP/1.0
// is handled elsewhere.
if (minorVersion >= 1) {
rr << "Connection: close\r\n"
}
true
} else if (minorVersion >= 1) {
logger.trace(s"Keeping ${conn} alive per default behavior of HTTP >= 1.1")
false
} else if (conn.fold(false)(_.hasKeepAlive)) {
logger.trace(
s"Keeping ${conn} alive due to explicit keep-alive option in request's Connection header"
)
false
} else {
logger.trace(s"Closing ${conn} per default behavior of HTTP/1.0")
true
}

/** Get the proper body encoder based on the request */
protected final def getEncoder(
req: Request[F],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private[blaze] class CachingChunkWriter[F[_]](
pipe.channelWrite(hbuff)
}
} else if (!chunk.isEmpty) {
writeBodyChunk(chunk, true).flatMap { _ =>
writeBodyChunk(chunk, flush = true).flatMap { _ =>
writeTrailer(pipe, trailer)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private[blaze] class FlushingChunkWriter[F[_]](pipe: TailStage[ByteBuffer], trai
else pipe.channelWrite(encodeChunk(chunk, Nil))

protected def writeEnd(chunk: Chunk[Byte]): Future[Boolean] = {
if (!chunk.isEmpty) writeBodyChunk(chunk, true).flatMap { _ =>
if (!chunk.isEmpty) writeBodyChunk(chunk, flush = true).flatMap { _ =>
writeTrailer(pipe, trailer)
}
else writeTrailer(pipe, trailer)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2014 http4s.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.http4s
package blaze.core.util

import org.http4s.util.Writer

/** A writer that does not write. Not to be confused with an
* [[EntityBodyWriter]].
*/
private[http4s] object NullWriter extends Writer {
def append(s: String): NullWriter.type = NullWriter
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,25 @@ class Http1WriterSpec extends CatsEffectSuite with DispatcherIOFixture {
runNonChunkedTests(
"CachingChunkWriter",
implicit dispatcher =>
tail => new CachingChunkWriter[IO](tail, IO.pure(Headers.empty), 1024 * 1024, false),
tail =>
new CachingChunkWriter[IO](
tail,
IO.pure(Headers.empty),
1024 * 1024,
omitEmptyContentLength = false,
),
)

runNonChunkedTests(
"CachingStaticWriter",
implicit dispatcher =>
tail => new CachingChunkWriter[IO](tail, IO.pure(Headers.empty), 1024 * 1024, false),
tail =>
new CachingChunkWriter[IO](
tail,
IO.pure(Headers.empty),
1024 * 1024,
omitEmptyContentLength = false,
),
)

def builder(tail: TailStage[ByteBuffer])(implicit D: Dispatcher[IO]): FlushingChunkWriter[IO] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,9 @@ private[blaze] class Http1ServerStage[F[_]](
// Need to decide which encoder and if to close on finish
val closeOnFinish = respConn
.map(_.hasClose)
.orElse {
req.headers.get[Connection].map(checkCloseConnection(_, rr))
}
.getOrElse(
parser.minorVersion() == 0
) // Finally, if nobody specifies, http 1.0 defaults to close
checkRequestCloseConnection(req.headers.get[Connection], parser.minorVersion(), rr)
)

// choose a body encoder. Will add a Transfer-Encoding header if necessary
val bodyEncoder: Http1Writer[F] =
Expand Down Expand Up @@ -289,7 +286,7 @@ private[blaze] class Http1ServerStage[F[_]](
rr,
parser.minorVersion(),
closeOnFinish,
false,
omitEmptyContentLength = false,
)

// TODO: pool shifting: https://github.com/http4s/http4s/blob/main/core/src/main/scala/org/http4s/internal/package.scala#L45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private[http4s] trait WebSocketSupport[F[_]] extends Http1ServerStage[F] {
.prepend(new WSFrameAggregator)
.prepend(new WebSocketDecoder(maxBufferSize.getOrElse(0)))

this.replaceTail(segment, true)
this.replaceTail(segment, startup = true)

case Failure(t) => fatalError(t, "Error writing Websocket upgrade response")
}(executionContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,26 @@ class BlazeServerMtlsSpec extends CatsEffectSuite {
*/
blazeServer(TLSParameters(needClientAuth = true).toSSLParameters)
.test("Server should send mTLS request correctly") { server =>
assertEquals(get(server, "/dummy", true), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US")
assertEquals(get(server, "/dummy"), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US")
}
blazeServer(TLSParameters(needClientAuth = true).toSSLParameters)
.test("Server should fail for invalid client auth") { server =>
assertNotEquals(get(server, "/dummy", false), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US")
assertNotEquals(
get(server, "/dummy", clientAuth = false),
"CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US",
)
}

/** Test "requested" auth mode
*/
blazeServer(TLSParameters(wantClientAuth = true).toSSLParameters)
.test("Server should send mTLS request correctly with optional auth") { server =>
assertEquals(get(server, "/dummy", true), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US")
assertEquals(get(server, "/dummy"), "CN=Test,OU=Test,O=Test,L=CA,ST=CA,C=US")
}

blazeServer(TLSParameters(wantClientAuth = true).toSSLParameters)
.test("Server should send mTLS request correctly without clientAuth") { server =>
assertEquals(get(server, "/noauth", false), "success")
assertEquals(get(server, "/noauth", clientAuth = false), "success")
}

}
Loading
Loading