Skip to content

Commit

Permalink
Keep path on baseUrl when combining baseUrl and url instead of throwi…
Browse files Browse the repository at this point in the history
…ng it away
  • Loading branch information
jmieghem committed Jun 18, 2020
1 parent 512f683 commit fb78bbf
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 fb78bbf

Please sign in to comment.