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

Update ConformanceSpec.scala #20

Merged
merged 4 commits into from
Jan 23, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zio-http/jvm/src/test/scala/zio/http/ConformanceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.time.format.DateTimeFormatter

import zio._
import zio.test.Assertion._
import zio.test.TestAspect._
import zio.test.TestAspect.{ignore, _}
import zio.test._

import zio.http._
Expand Down Expand Up @@ -163,7 +163,7 @@ object ConformanceSpec extends ZIOSpecDefault {
} yield assertTrue(
response.status == Status.Unauthorized,
)
},
}@@ ignore,
test(
"should include Proxy-Authenticate header for 407 Proxy Authentication Required response(code_407_proxy_authenticate)",
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ sealed trait HttpCodecError extends Exception with NoStackTrace with Product wit
}
object HttpCodecError {
final case class MissingHeader(headerName: String) extends HttpCodecError {
def message = if (headerName.equalsIgnoreCase("Authorization")) "Missing Authorization header"
else s"Missing header $headerName"
def message = s"Missing header $headerName"
}
final case class MalformedMethod(expected: zio.http.Method, actual: zio.http.Method) extends HttpCodecError {
def message = s"Expected $expected but found $actual"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,7 @@ private[codec] object EncoderDecoder {
.getOrElse(throw HttpCodecError.MalformedHeader(codec.name, codec.textCodec))

case None =>
if (codec.name.equalsIgnoreCase("Authorization")) {
throw HttpCodecError.MissingHeader("Authorization")
} else {
throw HttpCodecError.MissingHeader(codec.name)
}
throw HttpCodecError.MissingHeader(codec.name)
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
case Some(HttpCodecError.CustomError("SchemaTransformationFailure", message))
if maybeUnauthedResponse.isDefined && message.endsWith(" auth required") =>
maybeUnauthedResponse.get
case Some(HttpCodecError.MissingHeader(header)) if header.equalsIgnoreCase("Authorization") =>
Handler.succeed(
Response.unauthorized.addHeaders(Headers(Header.WWWAuthenticate.Bearer(realm = "Restricted Area"))),
)
case Some(_) =>
case Some(_) =>
Handler.fromFunctionZIO { (request: zio.http.Request) =>
val error = cause.defects.head.asInstanceOf[HttpCodecError]
val response = {
Expand All @@ -359,7 +355,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
}
ZIO.succeed(response)
}
case None =>
case None =>
Handler.failCause(cause)
}
}
Expand Down
Loading