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

fix(server): proper path segment decoding #3386

Merged
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
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
Loading