Sitelet https://github.com/twitter/finagle/commit/f40fe447494c81524900941c7311c697d575698c
Skip to content

Commit f40fe44

Browse files
ryanoneilljenkins
authored andcommitted
finagle-base-http: Make path Public for Uri
Problem / Solution finagle-base-http's `Uri` class is capable of parsing the full URI into a path and query parameters. Currently only the params are publicly accessible. In code in Twitter Server, providing access to both the params and the path would allow us to remove duplicated code. Let's provide access to the path publicly. JIRA Issues: CSL-9026 Differential Revision: https://phabricator.twitter.biz/D393893
1 parent 30d3d0e commit f40fe44

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎CHANGELOG.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Unreleased
1010
New Features
1111
~~~~~~~~~~~~
1212

13+
* finagle-base-http: The `Uri` class now provides access publicly to its
14+
`path`, which is the request uri without the query parameters.
15+
``PHAB_ID=D393893``
16+
1317
* finagle-mysql: Adding native support to finagle-mysql for MySQL JSON Data Type. A client
1418
can now use `jsonAsObjectOrNull[T]` or `getJsonAsObject[T]` APIs on `c.t.f.mysql.Row` to
1519
read the underlying json value as type `T` or use `jsonBytesOrNull` API to get a raw byte

‎finagle-base-http/src/main/scala/com/twitter/finagle/http/Uri.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object Uri {
2020
/**
2121
* Represents an immutable URI.
2222
*/
23-
final class Uri private (host: Option[String], path: String, query: Option[String]) {
23+
final class Uri private (host: Option[String], val path: String, query: Option[String]) {
2424

2525
def this(host: String, path: String, query: String) =
2626
this(Some(host), path, Some(query))

‎finagle-base-http/src/test/scala/com/twitter/finagle/http/UriTest.scala‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ class UriTest extends FunSuite {
2727
val uri = new Uri("twitter.com", "/whatever", "foo=bar")
2828
assert(uri.params.toMap == Map("foo" -> "bar"))
2929
}
30+
31+
test("Provides path when no query parameters") {
32+
val req = Request("/abcdef")
33+
val uri = Uri.fromRequest(req)
34+
assert(uri.path == "/abcdef")
35+
}
36+
37+
test("Provides path without query parameters") {
38+
val req = Request("/abc/def?ghi=jkl&mno=pqr")
39+
val uri = Uri.fromRequest(req)
40+
assert(uri.path == "/abc/def")
41+
}
3042
}

0 commit comments

Comments
 (0)