Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default localhost on our uri #1341

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/aws-http4s/src/smithy4s/aws/AwsClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object AwsClient {
val endpointPrefix = awsService.endpointPrefix.getOrElse(endpoint.id.name)
val baseUri = HttpUri(
scheme = HttpUriScheme.Https,
host = s"$endpointPrefix.$region.amazonaws.com",
host = Some(s"$endpointPrefix.$region.amazonaws.com"),
port = None,
path = IndexedSeq.empty,
queryParams = Map.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ final class HttpRequestSpec extends FunSuite {

val uri = HttpUri(
HttpUriScheme.Https,
"example.com",
Some("example.com"),
None,
IndexedSeq.empty,
Map.empty,
None
)
val request = HttpRequest(HttpMethod.GET, uri, Map.empty, "")
val resultUri = writer.write(request, Foo("hello")).uri
assertEquals(resultUri, uri.copy(host = "test.hello-other.example.com"))
assertEquals(
resultUri,
uri.copy(host = Some("test.hello-other.example.com"))
)
}

}
6 changes: 3 additions & 3 deletions modules/core/src/smithy4s/http/HttpRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ object HttpRequest {
request: HttpRequest[Body],
input: I
): HttpRequest[Body] = {
val hostPrefix = prefixEncoder.write(List.empty, input)
val hostPrefix = prefixEncoder.write(List.empty, input).mkString
val oldUri = request.uri
val newUri =
oldUri.copy(host = s"${hostPrefix.mkString}${oldUri.host}")
val prefixedHost = oldUri.host.map(host => s"$hostPrefix$host")
val newUri = oldUri.copy(host = prefixedHost)
request.copy(uri = newUri)
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/smithy4s/http/HttpUri.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package smithy4s.http

final case class HttpUri(
daddykotex marked this conversation as resolved.
Show resolved Hide resolved
scheme: HttpUriScheme,
host: String,
host: Option[String],
port: Option[Int],
/**
* A sequence of URL-decoded URI segment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ package object kernel {

Smithy4sHttpUri(
uriScheme,
uri.host.map(_.renderString).getOrElse("localhost"),
uri.host.map(_.renderString),
uri.port,
uri.path.segments.map(_.decoded()),
getQueryParams(uri),
Expand Down Expand Up @@ -98,10 +98,10 @@ package object kernel {

def fromSmithy4sHttpUri(uri: Smithy4sHttpUri): Uri = {
val path = Uri.Path.Root.addSegments(uri.path.map(Uri.Path.Segment(_)).toVector)

val authority = uri.host.map(h => Uri.Authority(host = Uri.RegName(h), port = uri.port))
Uri(
path = path,
authority = Some(Uri.Authority(host = Uri.RegName(uri.host), port = uri.port)),
authority = authority,
scheme = Some {
uri.scheme match {
case Smithy4sHttpUriScheme.Http => Uri.Scheme.http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ object Http4sConversionSpec extends SimpleIOSuite {
private def aSmithy4sUri(scheme: HttpUriScheme) =
smithy4s.http.HttpUri(
scheme = scheme,
host = "localhost",
host = None,
port = None,
path = IndexedSeq.empty,
queryParams = Map.empty,
Expand Down