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

Include bound path segments in request #146

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions cask/src/cask/main/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,17 @@ object Main{
.toList

dispatchTrie.lookup(decodedSegments, Vector()) match {
case None => Main.writeResponse(exchange, handleNotFound(Request(exchange, decodedSegments)))
case None => Main.writeResponse(exchange, handleNotFound(Request(exchange, decodedSegments, Map())))
case Some((methodMap, routeBindings, remaining)) =>
methodMap.get(effectiveMethod) match {
case None => Main.writeResponse(exchange, handleMethodNotAllowed(Request(exchange, remaining)))
case None => Main.writeResponse(exchange, handleMethodNotAllowed(Request(exchange, remaining, routeBindings)))
case Some((routes, metadata)) =>
val req = Request(exchange, remaining)
val req = Request(exchange, remaining, routeBindings)
Decorator.invoke(
req,
metadata.endpoint,
metadata.entryPoint.asInstanceOf[EntryPoint[Routes, _]],
routes,
routeBindings,
(mainDecorators ++ routes.decorators ++ metadata.decorators).toList,
Nil,
Nil
Expand Down
2 changes: 1 addition & 1 deletion cask/src/cask/model/Params.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.undertow.server.handlers.CookieImpl
case class QueryParams(value: Map[String, collection.Seq[String]])
case class RemainingPathSegments(value: Seq[String])

case class Request(exchange: HttpServerExchange, remainingPathSegments: Seq[String])
case class Request(exchange: HttpServerExchange, remainingPathSegments: Seq[String], boundPathSegments: Map[String, String])
extends geny.ByteData with geny.Readable {
import collection.JavaConverters._
lazy val cookies: Map[String, Cookie] = {
Expand Down
5 changes: 2 additions & 3 deletions cask/src/cask/router/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,21 @@ object Decorator{
endpoint: Endpoint[_, _, _, _],
entryPoint: EntryPoint[T, _],
routes: T,
routeBindings: Map[String, String],
remainingDecorators: List[Decorator[_, _, _, _]],
inputContexts: List[Any],
bindings: List[Map[String, Any]]): Result[Any] = try {
remainingDecorators match {
case head :: rest =>
head.asInstanceOf[Decorator[Any, Any, Any, Any]].wrapFunction(
ctx,
(ictx, args) => invoke(ctx, endpoint, entryPoint, routes, routeBindings, rest, ictx :: inputContexts, args :: bindings)
(ictx, args) => invoke(ctx, endpoint, entryPoint, routes, rest, ictx :: inputContexts, args :: bindings)
.asInstanceOf[Result[Nothing]]
)

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

val mergedEndpointBindings = endpointBindings ++ routeBindings.mapValues(endpoint.wrapPathSegment)
val mergedEndpointBindings = endpointBindings ++ ctx.boundPathSegments.mapValues(endpoint.wrapPathSegment)
val finalBindings = mergedEndpointBindings :: bindings

entryPoint
Expand Down
Loading