Skip to content

Commit

Permalink
should send 100 Continue before 101 Switching Protocols when both Upg…
Browse files Browse the repository at this point in the history
…rade and Expect headers are present
  • Loading branch information
varshith257 committed Sep 24, 2024
1 parent 414e317 commit 08f0019
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions zio-http/jvm/src/test/scala/zio/http/ServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,12 @@ object ServerSpec extends RoutesRunnableSpec {
test("should send 100 Continue before 101 Switching Protocols when both Upgrade and Expect headers are present") {
val upgradeRoute = Method.GET / "upgrade" -> Handler.fromZIO {
ZIO.succeed(
Response
.status(Status.Continue)
.addHeader(Header.Upgrade.withValue("https")),
) *> ZIO.succeed(
Response
.status(Status.SwitchingProtocols)
.addHeader(Header.Upgrade.withValue("https"))
.addHeader(Header.Connection.Upgrade),
)
}
Expand All @@ -538,11 +541,14 @@ object ServerSpec extends RoutesRunnableSpec {
.addHeader(Header.Upgrade.withValue("https"))

for {
response <- app.runZIO(request)
firstResponse <- app.runZIO(request) // This should be the 100 Continue response
secondResponse <- app.runZIO(request) // This should be the 101 Switching Protocols response

} yield assertTrue(
response.status == Status.Continue || response.status == Status.SwitchingProtocols, // The test will expect both statuses
response.headers.contains(Header.Upgrade.name),
response.headers.contains(Header.Connection.name),
firstResponse.status == Status.Continue, // Checks first response is 100 Continue
secondResponse.status == Status.SwitchingProtocols, // Checks second response is 101 Switching Protocols
secondResponse.headers.contains(Header.Upgrade.name),
secondResponse.headers.contains(Header.Connection.name),
)
} +
test("should return 400 Bad Request if Host header is missing") {
Expand Down

0 comments on commit 08f0019

Please sign in to comment.