Skip to content

Commit

Permalink
Merge pull request #1139 from jgelon/master
Browse files Browse the repository at this point in the history
Fix: Keep existing path on baseUrl
  • Loading branch information
Ronald Holshausen authored Jun 19, 2020
2 parents 152ecc1 + fb78bbf commit 9f21d62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ object HttpClientUtils {
}
} else {
if (encodePath) {
URIBuilder(baseUrl).setPath(url).build()
val builder = URIBuilder(baseUrl)
pathCombiner(builder, url)
} else {
URI(baseUrl + url)
}
}
}

fun pathCombiner(builder: URIBuilder, url: String): URI {
return if (builder.getPath() != null) {
builder.setPath(builder.getPath() + url).build()
} else {
builder.setPath(url).build()
}
}

fun isJsonResponse(contentType: ContentType) = contentType.mimeType == "application/json" ||
contentType.mimeType == "application/hal+json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class HttpClientUtilsSpec extends Specification {
'path with spaces' | '' | '/path/with spaces' | '/path/with%20spaces'
'Full URL with spaces' | '' | 'http://localhost:1234/path/with spaces' | 'http://localhost:1234/path/with%20spaces'
'no port' | 'http://localhost' | '/path/with spaces' | 'http://localhost/path/with%20spaces'
'Extra path' | 'http://localhost/sub' | '/extraPath/with spaces' | 'http://localhost/sub/extraPath/with%20spaces'
}

}

0 comments on commit 9f21d62

Please sign in to comment.