Skip to content

Commit

Permalink
refactor: make it's easy to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
hanrw committed Aug 28, 2024
1 parent 7207253 commit eeef583
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ interface ConnectionConfig {

private fun DefaultRequest.DefaultRequestBuilder.setupUrl(connectionConfig: ConnectionConfig) {
when (connectionConfig) {
is HostPortConnectionConfig -> {
url {
protocol =
connectionConfig.protocol()?.let { URLProtocol.createOrDefault(it) }
?: URLProtocol.HTTPS
host = connectionConfig.host()
connectionConfig.port()?.let { port = it }
}
}
is HostPortConnectionConfig -> setupHostPortConnectionConfig(connectionConfig)
is UrlBasedConnectionConfig -> url.takeFrom(connectionConfig.baseUrl())
}
}

is UrlBasedConnectionConfig -> {
connectionConfig.baseUrl().let { url.takeFrom(it) }
}
private fun DefaultRequest.DefaultRequestBuilder.setupHostPortConnectionConfig(config: HostPortConnectionConfig) {
url {
protocol = config.protocol()?.let { URLProtocol.createOrDefault(it) } ?: URLProtocol.HTTPS
host = config.host()
config.port()?.let { port = it }
}
}
}

0 comments on commit eeef583

Please sign in to comment.