Skip to content

Commit

Permalink
Fix path in client requests (#2316)
Browse files Browse the repository at this point in the history
* Fix path in client requests

* Add test
  • Loading branch information
vigoo authored Jul 27, 2023
1 parent fd7a239 commit ee76d96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private[zio] object NettyRequestEncoder {

// As per the spec, the path should contain only the relative path.
// Host and port information should be in the headers.
val path = replaceEmptyPathWithSlash(req.url).relative.encode
val path = replaceEmptyPathWithSlash(req.url).relative.addLeadingSlash.encode

val encodedReqHeaders = Conversions.headersToNetty(req.allHeaders)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ object NettyRequestEncoderSpec extends ZIOSpecDefault {
test("uri") {
check(anyClientParam) { params =>
val req = encode(params).map(_.uri())
assertZIO(req)(equalTo(params.url.relative.encode))
assertZIO(req)(equalTo(params.url.relative.addLeadingSlash.encode))
}
},
test("uri on Body.RandomAccessFile") {
check(HttpGen.clientParamsForFileBody()) { params =>
val req = encode(params).map(_.uri())
assertZIO(req)(equalTo(params.url.relative.encode))
assertZIO(req)(equalTo(params.url.relative.addLeadingSlash.encode))
}
},
),
Expand Down Expand Up @@ -121,9 +121,15 @@ object NettyRequestEncoderSpec extends ZIOSpecDefault {
test("url with an empty path and query params") {
check(clientParamWithEmptyPathAndQueryParams) { params =>
val uri = encode(params).map(_.uri)
assertZIO(uri)(not(equalTo(params.url.encode)))
assertZIO(uri)(not(equalTo(params.url.encode))) &&
assertZIO(uri)(equalTo(params.url.addLeadingSlash.encode))
}
},
test("leading slash added to path") {
val url = URL.decode("https://api.github.com").toOption.get / "something" / "else"
val req = Request(url = url)
val encoded = encode(req).map(_.uri)
assertZIO(encoded)(equalTo("/something/else"))
},
)
}

0 comments on commit ee76d96

Please sign in to comment.