Skip to content

Commit

Permalink
fix(server): proper path segment decoding (#3386)
Browse files Browse the repository at this point in the history
Co-authored-by: adamw <[email protected]>
  • Loading branch information
finalchild and adamw authored Dec 11, 2023
1 parent 8fa703b commit 19d08b1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sttp.tapir.server.finatra

import com.twitter.finagle.http.Request
import io.netty.handler.codec.http.QueryStringDecoder
import sttp.model.{Header, Method, QueryParams, Uri}
import sttp.tapir.{AttributeKey, AttributeMap}
import sttp.tapir.model.{ConnectionInfo, ServerRequest}
Expand All @@ -17,7 +16,7 @@ case class FinatraServerRequest(request: Request, attributes: AttributeMap = Att
override lazy val queryParameters: QueryParams =
QueryParams.fromMultiMap(request.params.keys.toList.map(k => k -> request.params.getAll(k).toList).toMap)
override lazy val pathSegments: List[String] = {
val segments = request.path.dropWhile(_ == '/').split("/").toList.map(QueryStringDecoder.decodeComponent)
val segments = uri.pathSegments.segments.map(_.v).filter(_.nonEmpty).toList
if (segments == List("")) Nil else segments // representing the root path as an empty list
}
override def underlying: Any = request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package sttp.tapir.server.vertx.decoders

import io.netty.handler.codec.http.QueryStringDecoder

import java.net.InetSocketAddress
import io.vertx.core.net.SocketAddress
import io.vertx.ext.web.RoutingContext
Expand All @@ -28,8 +26,7 @@ private[vertx] case class VertxServerRequest(rc: RoutingContext, attributes: Att
override lazy val headers: Seq[Header] = rc.request.headers.entries.asScala.iterator.map(e => Header(e.getKey, e.getValue)).toList
override lazy val queryParameters: QueryParams = Uri.unsafeParse(rc.request.uri()).params
override lazy val pathSegments: List[String] = {
val path = Option(rc.request.path).getOrElse("")
val segments = path.dropWhile(_ == '/').split("/").toList.map(QueryStringDecoder.decodeComponent)
val segments = uri.pathSegments.segments.map(_.v).filter(_.nonEmpty).toList
if (segments == List("")) Nil else segments // representing the root path as an empty list
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sttp.tapir.server.ziohttp
import sttp.model.{QueryParams, Uri, Header => SttpHeader, Method => SttpMethod}
import sttp.tapir.{AttributeKey, AttributeMap}
import sttp.tapir.model.{ConnectionInfo, ServerRequest}
import zio.http.Path
import zio.http.Request

import java.net.InetSocketAddress
Expand All @@ -18,7 +17,7 @@ case class ZioHttpServerRequest(req: Request, attributes: AttributeMap = Attribu
None
)
override def underlying: Any = req
override lazy val pathSegments: List[String] = req.url.path.segments.toList
override lazy val pathSegments: List[String] = uri.pathSegments.segments.map(_.v).filter(_.nonEmpty).toList
override lazy val queryParameters: QueryParams = QueryParams.fromMultiMap(req.url.queryParams.map)
override lazy val method: SttpMethod = SttpMethod(req.method.name.toUpperCase)
override lazy val uri: Uri = Uri.unsafeParse(req.url.encode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ class ZioHttpServerTest extends TestSuite {
createServerTest,
interpreter,
multipleValueHeaderSupport = false,
supportsUrlEncodedPathSegments = false,
supportsMultipleSetCookieHeaders = false,
invulnerableToUnsanitizedHeaders = false
).tests() ++
Expand Down

0 comments on commit 19d08b1

Please sign in to comment.