0

The below code seems to complete without errors however lower down in the stack spray.can.server.HttpServerConnection wants 'If-Match' header to have a specific format.
I feel that I'm missing maybe a rejection handler? Or do I have to turn off something?

Any Ideas?

api 22:29:56.251 | WARN  | root-actor-system-akka.actor.default-dispatcher-4 | akka://root-actor-system/user/IO-HTTP/listener-0/2 | spray.can.server.HttpServerConnection | Illegal request header: Illegal 'If-Match' header: Invalid input 's', expected $timesIf$minusMatch (line 1, pos 1): somehashfunctionvalue

Route:

override def putObjectRoute = (path("api" / "models" / Segment / "objects") & authenticatedJsonRoute) {
    (modeledSystemName, tenantName, authInfo) =>
      put {
        entity(as[ModeledObject]) { obje =>
          etag(obje, hashfunction) {
            onComplete(service.updateObject(modeledSystemName, tenantName, obje)) {
              case Success(_) => complete(NoContent)
              case Failure(ex) =>
                log.error(ex.getMessage)
                complete(InternalServerError, s"An error occurred: ${ex.getMessage}")
            }
          }
        }

Directive:

trait OCCETag {

  def etag[T](entity: T, f: (String, T) => Boolean): Directive0 = optionalHeaderValueByName("If-Match").flatMap {
    case Some(etag) => mapInnerRoute { route =>
      val e = entity
      ctx => {
        def complete304() = ctx.complete(HttpResponse(NotModified))
        def complete412() = ctx.complete(PreconditionFailed)
        if (f(etag, e)) pass else complete412()
      }
    }
    case None => reject(MissingHeaderRejection("If-Match"))
  }
}
Adam Wayland
  • 354
  • 1
  • 2
  • 9

1 Answers1

0

I found the solution. I changed pass to reader route(ctx). Basically the pass does not hand the context thorough to the directive.

Adam Wayland
  • 354
  • 1
  • 2
  • 9