Skip to content

Commit c0ed742

Browse files
authored
Include bound path segments in request (#146)
This makes it possible to access raw path parameters in a decorator.
1 parent 3200adf commit c0ed742

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

cask/src/cask/main/Main.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,17 @@ object Main{
107107
.toList
108108

109109
dispatchTrie.lookup(decodedSegments, Vector()) match {
110-
case None => Main.writeResponse(exchange, handleNotFound(Request(exchange, decodedSegments)))
110+
case None => Main.writeResponse(exchange, handleNotFound(Request(exchange, decodedSegments, Map())))
111111
case Some((methodMap, routeBindings, remaining)) =>
112112
methodMap.get(effectiveMethod) match {
113-
case None => Main.writeResponse(exchange, handleMethodNotAllowed(Request(exchange, remaining)))
113+
case None => Main.writeResponse(exchange, handleMethodNotAllowed(Request(exchange, remaining, routeBindings)))
114114
case Some((routes, metadata)) =>
115-
val req = Request(exchange, remaining)
115+
val req = Request(exchange, remaining, routeBindings)
116116
Decorator.invoke(
117117
req,
118118
metadata.endpoint,
119119
metadata.entryPoint.asInstanceOf[EntryPoint[Routes, _]],
120120
routes,
121-
routeBindings,
122121
(mainDecorators ++ routes.decorators ++ metadata.decorators).toList,
123122
Nil,
124123
Nil

cask/src/cask/model/Params.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import io.undertow.server.handlers.CookieImpl
99
case class QueryParams(value: Map[String, collection.Seq[String]])
1010
case class RemainingPathSegments(value: Seq[String])
1111

12-
case class Request(exchange: HttpServerExchange, remainingPathSegments: Seq[String])
12+
case class Request(exchange: HttpServerExchange, remainingPathSegments: Seq[String], boundPathSegments: Map[String, String])
1313
extends geny.ByteData with geny.Readable {
1414
import collection.JavaConverters._
1515
lazy val cookies: Map[String, Cookie] = {

cask/src/cask/router/Decorators.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,21 @@ object Decorator{
3737
endpoint: Endpoint[_, _, _, _],
3838
entryPoint: EntryPoint[T, _],
3939
routes: T,
40-
routeBindings: Map[String, String],
4140
remainingDecorators: List[Decorator[_, _, _, _]],
4241
inputContexts: List[Any],
4342
bindings: List[Map[String, Any]]): Result[Any] = try {
4443
remainingDecorators match {
4544
case head :: rest =>
4645
head.asInstanceOf[Decorator[Any, Any, Any, Any]].wrapFunction(
4746
ctx,
48-
(ictx, args) => invoke(ctx, endpoint, entryPoint, routes, routeBindings, rest, ictx :: inputContexts, args :: bindings)
47+
(ictx, args) => invoke(ctx, endpoint, entryPoint, routes, rest, ictx :: inputContexts, args :: bindings)
4948
.asInstanceOf[Result[Nothing]]
5049
)
5150

5251
case Nil =>
5352
endpoint.wrapFunction(ctx, { (ictx: Any, endpointBindings: Map[String, Any]) =>
5453

55-
val mergedEndpointBindings = endpointBindings ++ routeBindings.mapValues(endpoint.wrapPathSegment)
54+
val mergedEndpointBindings = endpointBindings ++ ctx.boundPathSegments.mapValues(endpoint.wrapPathSegment)
5655
val finalBindings = mergedEndpointBindings :: bindings
5756

5857
entryPoint

0 commit comments

Comments
 (0)