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

fix: make content-type header case insensitive & remove support for ws #7

Merged
merged 1 commit into from
Jun 6, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ object MediatorAgent {
def didCommApp = {
Http.collectZIO[Request] {
case req @ Method.GET -> !! if req.headersAsList.exists { h =>
h.key == "content-type" &&
(h.value == MediaTypes.SIGNED || h.value == MediaTypes.ENCRYPTED.typ)
h.key.toString.toLowerCase == "content-type" &&
(h.value.toString.startsWith(MediaTypes.SIGNED.typ) ||
h.value.toString.startsWith(MediaTypes.ENCRYPTED.typ))
} =>
for {
agent <- ZIO.service[MediatorAgent]
Expand All @@ -224,8 +225,9 @@ object MediatorAgent {
ret <- agent.websocketListenerApp(annotationMap)
} yield (ret)
case req @ Method.POST -> !! if req.headersAsList.exists { h =>
h.key == "content-type" &&
(h.value == MediaTypes.SIGNED || h.value == MediaTypes.ENCRYPTED.typ)
h.key.toString.toLowerCase == "content-type" &&
(h.value.toString.startsWith(MediaTypes.SIGNED.typ) ||
h.value.toString.startsWith(MediaTypes.ENCRYPTED.typ))
} =>
for {
agent <- ZIO.service[MediatorAgent]
Expand All @@ -240,16 +242,11 @@ object MediatorAgent {

// TODO [return_route extension](https://github.com/decentralized-identity/didcomm-messaging/blob/main/extensions/return_route/main.md)
case req @ Method.POST -> !! =>
for {
agent <- ZIO.service[MediatorAgent]
data <- req.body.asString
ret <- agent
.receiveMessage(data, None)
.mapError(fail => DidException(fail))
} yield Response
.text(s"The content-type must be ${MediaTypes.SIGNED.typ} or ${MediaTypes.ENCRYPTED.typ}")
// .copy(status = Status.BadRequest) but ok for now

ZIO.succeed(
Response
.text(s"The content-type must be ${MediaTypes.SIGNED.typ} or ${MediaTypes.ENCRYPTED.typ}")
.copy(status = Status.BadRequest)
)
}: Http[
Operations & Resolver & MessageDispatcher & MediatorAgent & Ref[MediatorDB],
Throwable,
Expand Down