diff options
author | vlad <vlad@driver.xyz> | 2017-02-28 11:19:03 -0800 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2017-02-28 11:19:03 -0800 |
commit | 43c29ea035c5d50789d42e55482d49640db4aa75 (patch) | |
tree | 8ead2eed99d212a8cddca845110784247b194bc7 /src/main/scala | |
parent | 93349b72cff2946ba449faf122f234e3c330ce11 (diff) | |
download | driver-core-0.10.16.tar.gz driver-core-0.10.16.tar.bz2 driver-core-0.10.16.zip |
Need less data to extract ServiceRequestContextv0.10.16
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/app.scala | 10 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/rest.scala | 14 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/main/scala/xyz/driver/core/app.scala b/src/main/scala/xyz/driver/core/app.scala index 68c7cf0..deb0e6a 100644 --- a/src/main/scala/xyz/driver/core/app.scala +++ b/src/main/scala/xyz/driver/core/app.scala @@ -71,7 +71,7 @@ object app { val _ = Future { http.bindAndHandle(route2HandlerFlow(handleExceptions(ExceptionHandler(exceptionHandler)) { ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.extractTrackingId(ctx.request) log.audit(s"Received request ${ctx.request} with tracking id $trackingId") val contextWithTrackingId = @@ -93,26 +93,26 @@ object app { case is: IllegalStateException => ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.extractTrackingId(ctx.request) log.debug(s"Request is not allowed to ${ctx.request.uri} ($trackingId)", is) complete(HttpResponse(BadRequest, entity = is.getMessage))(ctx) case cm: ConcurrentModificationException => ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.extractTrackingId(ctx.request) log.audit(s"Concurrent modification of the resource ${ctx.request.uri} ($trackingId)", cm) complete( HttpResponse(Conflict, entity = "Resource was changed concurrently, try requesting a newer version"))(ctx) case sex: SQLException => ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.extractTrackingId(ctx.request) log.audit(s"Database exception for the resource ${ctx.request.uri} ($trackingId)", sex) complete(HttpResponse(InternalServerError, entity = "Data access error"))(ctx) case t: Throwable => ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.extractTrackingId(ctx.request) log.error(s"Request to ${ctx.request.uri} could not be handled normally ($trackingId)", t) complete(HttpResponse(InternalServerError, entity = t.getMessage))(ctx) } diff --git a/src/main/scala/xyz/driver/core/rest.scala b/src/main/scala/xyz/driver/core/rest.scala index d3e7f8a..8bd200e 100644 --- a/src/main/scala/xyz/driver/core/rest.scala +++ b/src/main/scala/xyz/driver/core/rest.scala @@ -46,19 +46,19 @@ object rest { import akka.http.scaladsl.server._ import Directives._ - def serviceContext: Directive1[ServiceRequestContext] = extract(ctx => extractServiceContext(ctx)) + def serviceContext: Directive1[ServiceRequestContext] = extract(ctx => extractServiceContext(ctx.request)) - def extractServiceContext(ctx: RequestContext): ServiceRequestContext = - ServiceRequestContext(extractTrackingId(ctx), extractContextHeaders(ctx)) + def extractServiceContext(request: HttpRequest): ServiceRequestContext = + ServiceRequestContext(extractTrackingId(request), extractContextHeaders(request)) - def extractTrackingId(ctx: RequestContext): String = { - ctx.request.headers + def extractTrackingId(request: HttpRequest): String = { + request.headers .find(_.name == ContextHeaders.TrackingIdHeader) .fold(java.util.UUID.randomUUID.toString)(_.value()) } - def extractContextHeaders(ctx: RequestContext): Map[String, String] = { - ctx.request.headers.filter { h => + def extractContextHeaders(request: HttpRequest): Map[String, String] = { + request.headers.filter { h => h.name === ContextHeaders.AuthenticationTokenHeader || h.name === ContextHeaders.TrackingIdHeader // || ContextHeaders.LinkerD.isLinkerD(h.lowercaseName) } map { header => |