I have a scenario where I want to return some data in an
OPTIONS
call. The call works fine with a core http4k router, but if I wrap it in a
contract
, then the contract router never calls my handler and returns an empty 200. Presumably, this was done with the assumption that
OPTIONS
doesn't make much sense in a RESTP API, but that isn't always the case.
Is this phenomenon intentional? Is there a way to prevent it?
@Test
fun options() {
val handler = contract {
routes += "/v1/things" bindContract Method.OPTIONS to { _ ->
Response(Status.OK).body("lolcats")
}
}
val resp = handler(Request(Method.OPTIONS, "/v1/things"))
resp shouldHaveStatus Status.OK
resp shouldHaveBody "lolcats"
}
Body: expected:<"lolcats"> but was:<<empty string>>