From 2df7a28a3a231e5d514f5280861158d39f8b1f37 Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Tue, 6 Jun 2023 17:23:03 +0100 Subject: [PATCH] fix: make content-type header case insensitive & remove support for ws (#7) Signed-off-by: Fabio Pinheiro --- .../did/comm/mediator/MediatorAgent.scala | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/did-mediator/src/main/scala/fmgp/did/comm/mediator/MediatorAgent.scala b/did-mediator/src/main/scala/fmgp/did/comm/mediator/MediatorAgent.scala index 43074ebf..7738e238 100644 --- a/did-mediator/src/main/scala/fmgp/did/comm/mediator/MediatorAgent.scala +++ b/did-mediator/src/main/scala/fmgp/did/comm/mediator/MediatorAgent.scala @@ -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] @@ -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] @@ -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,