Skip to content

Commit

Permalink
Reverted constructUrlFromInputs to previous implementation.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Feb 5, 2024
1 parent 32d70e9 commit 5511efb
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import org.opensearch.core.xcontent.XContentBuilder
import org.opensearch.core.xcontent.XContentParser
import org.opensearch.core.xcontent.XContentParserUtils
import java.io.IOException
import java.lang.StringBuilder
import java.net.URI
import java.net.URISyntaxException

val ILLEGAL_PATH_PARAMETER_CHARACTERS = arrayOf(':', '"', '+', '\\', '|', '?', '#', '>', '<', ' ')

Expand Down Expand Up @@ -214,21 +214,23 @@ data class ClusterMetricsInput(
* @return The constructed [URI].
*/
private fun constructUrlFromInputs(): URI {
val fullPath = StringBuilder()
.append(path.trim('/'))

if (pathParams.isNotEmpty())
fullPath
.append('/')
.append(pathParams.trim('/'))

val uriBuilder = URIBuilder()
.setScheme(SUPPORTED_SCHEME)
.setHost(SUPPORTED_HOST)
.setPort(SUPPORTED_PORT)
.setPath(fullPath.toString())

return uriBuilder.build()
/**
* this try-catch block is required due to a httpcomponents 5.1.x library issue
* it auto encodes path params in the url.
*/
return try {
val formattedPath = if (path.startsWith("/") || path.isBlank()) path else "/$path"
val formattedPathParams = if (pathParams.startsWith("/") || pathParams.isBlank()) pathParams else "/$pathParams"
val uriBuilder = URIBuilder("$SUPPORTED_SCHEME://$SUPPORTED_HOST:$SUPPORTED_PORT$formattedPath$formattedPathParams")
uriBuilder.build()
} catch (ex: URISyntaxException) {
val uriBuilder = URIBuilder()
.setScheme(SUPPORTED_SCHEME)
.setHost(SUPPORTED_HOST)
.setPort(SUPPORTED_PORT)
.setPath(path + pathParams)
uriBuilder.build()
}
}

/**
Expand Down

0 comments on commit 5511efb

Please sign in to comment.