diff --git a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/util/HttpClientUtils.kt b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/util/HttpClientUtils.kt index 8c0a22e345..0215516922 100644 --- a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/util/HttpClientUtils.kt +++ b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/util/HttpClientUtils.kt @@ -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" } diff --git a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/util/HttpClientUtilsSpec.groovy b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/util/HttpClientUtilsSpec.groovy index dd4595ab2f..d3e48bae6c 100644 --- a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/util/HttpClientUtilsSpec.groovy +++ b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/util/HttpClientUtilsSpec.groovy @@ -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' } }