-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make `Scheme` a type * introduce new Endpoint type * use endpoint as storage in `HTTPClient.Request` * fix merge conflicts * rename Endpoint to DeconstructedURL * swift-format * make `DeconstructedURL` properties `var`'s * move scheme into global namespace - rename `useTLS` to `usesTLS` where posible without breaking public API - only import Foundation.URL * fix review comments
- Loading branch information
Showing
6 changed files
with
200 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the AsyncHTTPClient open source project | ||
// | ||
// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import struct Foundation.URL | ||
|
||
struct DeconstructedURL { | ||
var scheme: Scheme | ||
var connectionTarget: ConnectionTarget | ||
var uri: String | ||
|
||
init( | ||
scheme: Scheme, | ||
connectionTarget: ConnectionTarget, | ||
uri: String | ||
) { | ||
self.scheme = scheme | ||
self.connectionTarget = connectionTarget | ||
self.uri = uri | ||
} | ||
} | ||
|
||
extension DeconstructedURL { | ||
init(url: URL) throws { | ||
guard let schemeString = url.scheme else { | ||
throw HTTPClientError.emptyScheme | ||
} | ||
guard let scheme = Scheme(rawValue: schemeString.lowercased()) else { | ||
throw HTTPClientError.unsupportedScheme(schemeString) | ||
} | ||
|
||
switch scheme { | ||
case .http, .https: | ||
guard let host = url.host, !host.isEmpty else { | ||
throw HTTPClientError.emptyHost | ||
} | ||
self.init( | ||
scheme: scheme, | ||
connectionTarget: .init(remoteHost: host, port: url.port ?? scheme.defaultPort), | ||
uri: url.uri | ||
) | ||
|
||
case .httpUnix, .httpsUnix: | ||
guard let socketPath = url.host, !socketPath.isEmpty else { | ||
throw HTTPClientError.missingSocketPath | ||
} | ||
self.init( | ||
scheme: scheme, | ||
connectionTarget: .unixSocket(path: socketPath), | ||
uri: url.uri | ||
) | ||
|
||
case .unix: | ||
let socketPath = url.baseURL?.path ?? url.path | ||
let uri = url.baseURL != nil ? url.uri : "/" | ||
guard !socketPath.isEmpty else { | ||
throw HTTPClientError.missingSocketPath | ||
} | ||
self.init( | ||
scheme: scheme, | ||
connectionTarget: .unixSocket(path: socketPath), | ||
uri: uri | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.