Skip to content

Commit

Permalink
fix: make content-type header case insensitive & remove support for ws (
Browse files Browse the repository at this point in the history
#7)

Signed-off-by: Fabio Pinheiro <fabiomgpinheiro@gmail.com>

Signed-off-by: Shailesh Patil <shailesh.patil@iohk.io>
  • Loading branch information
FabioPinheiro authored and mineme0110 committed May 1, 2024
1 parent 4f206d1 commit c2f064e
Showing 1 changed file with 11 additions and 14 deletions.
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

0 comments on commit c2f064e

Please sign in to comment.