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

Allow caching of POST requests. #152

Merged
merged 1 commit into from
Jun 19, 2019
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
12 changes: 5 additions & 7 deletions src/main/scala/org/phenoscape/kb/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import com.typesafe.config.ConfigFactory
import akka.actor.ActorSystem
import akka.event.Logging
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.model.{HttpHeader, HttpMethod, StatusCodes, Uri, headers}
import akka.http.scaladsl.model.HttpMethods.GET
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.Uri
import akka.http.scaladsl.model.headers
import akka.http.scaladsl.model.HttpMethods.POST
import akka.http.scaladsl.model.headers.ContentDispositionTypes
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.server.HttpApp
Expand Down Expand Up @@ -72,10 +70,10 @@ object Main extends HttpApp with App {
}
}

val cacheKeyer: PartialFunction[RequestContext, (Uri, Option[HttpHeader])] = {
case r: RequestContext if (r.request.method == GET) => (r.request.uri, r.request.headers.find(_.is("accept")))
val cacheKeyer: PartialFunction[RequestContext, (Uri, Option[HttpHeader], HttpMethod)] = {
case r: RequestContext if (r.request.method == GET || r.request.method == POST) => (r.request.uri, r.request.headers.find(_.is("accept")), r.request.method)
}
val memoryCache = routeCache[(Uri, Option[HttpHeader])]
val memoryCache = routeCache[(Uri, Option[HttpHeader], HttpMethod)]

val conf = ConfigFactory.load()
val serverPort = conf.getInt("kb-services.port")
Expand Down