diff --git a/Examples/ElizaSharedSources/AppSources/MessagingViewModel.swift b/Examples/ElizaSharedSources/AppSources/MessagingViewModel.swift index ced4e1f9..dcc12dda 100644 --- a/Examples/ElizaSharedSources/AppSources/MessagingViewModel.swift +++ b/Examples/ElizaSharedSources/AppSources/MessagingViewModel.swift @@ -49,7 +49,7 @@ final class UnaryMessagingViewModel: MessagingViewModel { init(protocolOption: ProtocolClientOption) { self.protocolClient = ProtocolClient( - target: "https://demo.connect.build", + host: "https://demo.connect.build", httpClient: URLSessionHTTPClient(), ProtoClientOption(), // Send protobuf binary on the wire protocolOption // Specify the protocol to use for the client @@ -87,7 +87,7 @@ final class BidirectionalStreamingMessagingViewModel: MessagingViewModel { init(protocolOption: ProtocolClientOption) { self.protocolClient = ProtocolClient( - target: "https://demo.connect.build", + host: "https://demo.connect.build", httpClient: URLSessionHTTPClient(), ProtoClientOption(), // Send protobuf binary on the wire protocolOption // Specify the protocol to use for the client diff --git a/Libraries/Connect/Implementation/Options/ConnectClientOption.swift b/Libraries/Connect/Implementation/Options/ConnectClientOption.swift index 4246c865..990bec1d 100644 --- a/Libraries/Connect/Implementation/Options/ConnectClientOption.swift +++ b/Libraries/Connect/Implementation/Options/ConnectClientOption.swift @@ -66,7 +66,7 @@ extension ConnectInterceptor: Interceptor { } return HTTPRequest( - target: request.target, + url: request.url, contentType: request.contentType, headers: headers, message: finalRequestBody @@ -123,7 +123,7 @@ extension ConnectInterceptor: Interceptor { headers[HeaderConstants.connectStreamingAcceptEncoding] = self.config .acceptCompressionPoolNames() return HTTPRequest( - target: request.target, + url: request.url, contentType: request.contentType, headers: headers, message: request.message diff --git a/Libraries/Connect/Implementation/Options/GRPCWebClientOption.swift b/Libraries/Connect/Implementation/Options/GRPCWebClientOption.swift index 7e738e0b..989745ba 100644 --- a/Libraries/Connect/Implementation/Options/GRPCWebClientOption.swift +++ b/Libraries/Connect/Implementation/Options/GRPCWebClientOption.swift @@ -50,7 +50,7 @@ extension GRPCWebInterceptor: Interceptor { ) return HTTPRequest( - target: request.target, + url: request.url, // Override the content type to be gRPC Web. contentType: "application/grpc-web+\(self.config.codec.name())", headers: request.headers.addingGRPCWebHeaders(using: self.config), @@ -127,7 +127,7 @@ extension GRPCWebInterceptor: Interceptor { return StreamFunction( requestFunction: { request in return HTTPRequest( - target: request.target, + url: request.url, // Override the content type to be gRPC Web. contentType: "application/grpc-web+\(self.config.codec.name())", headers: request.headers.addingGRPCWebHeaders(using: self.config), diff --git a/Libraries/Connect/Implementation/ProtocolClient.swift b/Libraries/Connect/Implementation/ProtocolClient.swift index b4aa71df..ee74ce52 100644 --- a/Libraries/Connect/Implementation/ProtocolClient.swift +++ b/Libraries/Connect/Implementation/ProtocolClient.swift @@ -22,7 +22,7 @@ public final class ProtocolClient { /// Instantiate a new client. /// - /// - parameter target: The target host (e.g., https://buf.build). + /// - parameter host: The target host (e.g., https://buf.build). /// - parameter httpClient: HTTP client to use for performing requests. /// - parameter options: Series of options with which to configure the client. /// Identity and gzip compression implementations are provided by default @@ -31,10 +31,10 @@ public final class ProtocolClient { /// Additional compression implementations may be specified using custom /// options. public init( - target: String, httpClient: HTTPClientInterface, _ options: ProtocolClientOption... + host: String, httpClient: HTTPClientInterface, _ options: ProtocolClientOption... ) { var config = ProtocolClientConfig.withDefaultOptions( - andTarget: target, httpClient: httpClient + andHost: host, httpClient: httpClient ) for option in options { config = option.apply(config) @@ -44,7 +44,7 @@ public final class ProtocolClient { /// Instantiate a new client. /// - /// - parameter target: The target host (e.g., https://buf.build). + /// - parameter host: The target host (e.g., https://buf.build). /// - parameter httpClient: HTTP client to use for performing requests. /// - parameter options: Series of options with which to configure the client. /// Identity and gzip compression implementations are provided by default @@ -53,10 +53,10 @@ public final class ProtocolClient { /// Additional compression implementations may be specified using custom /// options. public init( - target: String, httpClient: HTTPClientInterface, options: [ProtocolClientOption] + host: String, httpClient: HTTPClientInterface, options: [ProtocolClientOption] ) { var config = ProtocolClientConfig.withDefaultOptions( - andTarget: target, httpClient: httpClient + andHost: host, httpClient: httpClient ) for option in options { config = option.apply(config) @@ -67,10 +67,10 @@ public final class ProtocolClient { private extension ProtocolClientConfig { static func withDefaultOptions( - andTarget target: String, httpClient: HTTPClientInterface + andHost host: String, httpClient: HTTPClientInterface ) -> Self { var config = ProtocolClientConfig( - target: target, + host: host, httpClient: httpClient, compressionMinBytes: nil, compressionName: nil, @@ -112,9 +112,9 @@ extension ProtocolClient: ProtocolClientInterface { } let chain = self.config.createInterceptorChain().unaryFunction() - let url = URL(string: path, relativeTo: URL(string: self.config.target))! + let url = URL(string: path, relativeTo: URL(string: self.config.host))! let request = chain.requestFunction(HTTPRequest( - target: url, + url: url, contentType: "application/\(codec.name())", headers: headers, message: data @@ -273,9 +273,9 @@ extension ProtocolClient: ProtocolClientInterface { ) -> RequestCallbacks { let codec = self.config.codec let chain = self.config.createInterceptorChain().streamFunction() - let url = URL(string: path, relativeTo: URL(string: self.config.target))! + let url = URL(string: path, relativeTo: URL(string: self.config.host))! let request = chain.requestFunction(HTTPRequest( - target: url, + url: url, contentType: "application/connect+\(codec.name())", headers: headers, message: nil diff --git a/Libraries/Connect/Implementation/ProtocolClientConfig.swift b/Libraries/Connect/Implementation/ProtocolClientConfig.swift index 12ae46d2..a093df12 100644 --- a/Libraries/Connect/Implementation/ProtocolClientConfig.swift +++ b/Libraries/Connect/Implementation/ProtocolClientConfig.swift @@ -17,7 +17,7 @@ import Foundation /// Set of configuration (usually modified through `ClientOption` types) used to set up clients. public struct ProtocolClientConfig { /// The target host (e.g., https://buf.build). - public let target: String + public let host: String /// The client to use for performing requests. public let httpClient: HTTPClientInterface /// The minimum number of bytes that a request message should be for compression to be used. @@ -41,7 +41,7 @@ public struct ProtocolClientConfig { interceptors: [(ProtocolClientConfig) -> Interceptor]? = nil ) -> Self { return .init( - target: self.target, + host: self.host, httpClient: self.httpClient, compressionMinBytes: compressionMinBytes ?? self.compressionMinBytes, compressionName: compressionName ?? self.compressionName, diff --git a/Libraries/Connect/Implementation/URLSessionHTTPClient.swift b/Libraries/Connect/Implementation/URLSessionHTTPClient.swift index df72221b..a3551df7 100644 --- a/Libraries/Connect/Implementation/URLSessionHTTPClient.swift +++ b/Libraries/Connect/Implementation/URLSessionHTTPClient.swift @@ -171,7 +171,7 @@ extension Code { private extension URLRequest { init(httpRequest: HTTPRequest) { - self.init(url: httpRequest.target) + self.init(url: httpRequest.url) self.httpMethod = "POST" self.httpBody = httpRequest.message self.setValue(httpRequest.contentType, forHTTPHeaderField: HeaderConstants.contentType) diff --git a/Libraries/Connect/Interfaces/HTTPRequest.swift b/Libraries/Connect/Interfaces/HTTPRequest.swift index 03eb0b65..c022029f 100644 --- a/Libraries/Connect/Interfaces/HTTPRequest.swift +++ b/Libraries/Connect/Interfaces/HTTPRequest.swift @@ -17,7 +17,7 @@ import Foundation /// HTTP request used for sending primitive data to the server. public struct HTTPRequest { /// Target URL for the request. - public let target: URL + public let url: URL /// Value to assign to the `content-type` header. public let contentType: String /// Additional outbound headers for the request. @@ -25,8 +25,8 @@ public struct HTTPRequest { /// Body data to send with the request. public let message: Data? - public init(target: URL, contentType: String, headers: Headers, message: Data?) { - self.target = target + public init(url: URL, contentType: String, headers: Headers, message: Data?) { + self.url = url self.contentType = contentType self.headers = headers self.message = message diff --git a/Tests/ConnectLibraryTests/ConnectCrosstests/CrosstestClients.swift b/Tests/ConnectLibraryTests/ConnectCrosstests/CrosstestClients.swift index 353e4a48..c3702ae1 100644 --- a/Tests/ConnectLibraryTests/ConnectCrosstests/CrosstestClients.swift +++ b/Tests/ConnectLibraryTests/ConnectCrosstests/CrosstestClients.swift @@ -25,10 +25,10 @@ final class CrosstestClients { let httpClient = CrosstestHTTPClient( timeout: timeout, delayAfterChallenge: responseDelay ) - let target = "https://localhost:8081" + let host = "https://localhost:8081" self.connectJSONClient = ProtocolClient( - target: target, + host: host, httpClient: httpClient, ConnectClientOption(), JSONClientOption(), @@ -36,7 +36,7 @@ final class CrosstestClients { GzipCompressionOption() ) self.connectProtoClient = ProtocolClient( - target: target, + host: host, httpClient: httpClient, ConnectClientOption(), ProtoClientOption(), @@ -44,7 +44,7 @@ final class CrosstestClients { GzipCompressionOption() ) self.grpcWebJSONClient = ProtocolClient( - target: target, + host: host, httpClient: httpClient, GRPCWebClientOption(), JSONClientOption(), @@ -52,7 +52,7 @@ final class CrosstestClients { GzipCompressionOption() ) self.grpcWebProtoClient = ProtocolClient( - target: target, + host: host, httpClient: httpClient, GRPCWebClientOption(), ProtoClientOption(), diff --git a/Tests/ConnectLibraryTests/ConnectTests/InterceptorChainTests.swift b/Tests/ConnectLibraryTests/ConnectTests/InterceptorChainTests.swift index cc48eb5d..a699a6c5 100644 --- a/Tests/ConnectLibraryTests/ConnectTests/InterceptorChainTests.swift +++ b/Tests/ConnectLibraryTests/ConnectTests/InterceptorChainTests.swift @@ -27,7 +27,7 @@ private struct MockUnaryInterceptor: Interceptor { headers["filter-chain", default: []].append(self.headerID) self.requestExpectation.fulfill() return HTTPRequest( - target: request.target, + url: request.url, contentType: request.contentType, headers: headers, message: request.message @@ -72,7 +72,7 @@ private struct MockStreamInterceptor: Interceptor { headers["filter-chain", default: []].append(self.headerID) self.requestExpectation.fulfill() return HTTPRequest( - target: request.target, + url: request.url, contentType: request.contentType, headers: headers, message: request.message @@ -105,7 +105,7 @@ private struct MockStreamInterceptor: Interceptor { final class InterceptorChainTests: XCTestCase { private let config = ProtocolClientConfig( - target: "https://buf.build", httpClient: CrosstestHTTPClient(timeout: 60), + host: "https://buf.build", httpClient: CrosstestHTTPClient(timeout: 60), compressionMinBytes: nil, compressionName: nil, compressionPools: [:], codec: JSONCodec(), interceptors: [] ) @@ -136,7 +136,7 @@ final class InterceptorChainTests: XCTestCase { ).unaryFunction() let interceptedRequest = chain.requestFunction(HTTPRequest( - target: try XCTUnwrap(URL(string: "https://buf.build/mock")), + url: try XCTUnwrap(URL(string: "https://buf.build/mock")), contentType: "application/json", headers: Headers(), message: nil @@ -199,7 +199,7 @@ final class InterceptorChainTests: XCTestCase { ).streamFunction() let interceptedRequest = chain.requestFunction(HTTPRequest( - target: try XCTUnwrap(URL(string: "https://buf.build/mock")), + url: try XCTUnwrap(URL(string: "https://buf.build/mock")), contentType: "application/json", headers: Headers(), message: nil diff --git a/Tests/ConnectLibraryTests/ConnectTests/ProtocolClientConfigTests.swift b/Tests/ConnectLibraryTests/ConnectTests/ProtocolClientConfigTests.swift index cf5813fd..8c412479 100644 --- a/Tests/ConnectLibraryTests/ConnectTests/ProtocolClientConfigTests.swift +++ b/Tests/ConnectLibraryTests/ConnectTests/ProtocolClientConfigTests.swift @@ -19,7 +19,7 @@ import XCTest final class ProtocolClientConfigTests: XCTestCase { func testCompressionPoolsWithIdentityAndGzip() { var config = ProtocolClientConfig( - target: "https://buf.build", httpClient: URLSessionHTTPClient(), + host: "https://buf.build", httpClient: URLSessionHTTPClient(), compressionMinBytes: nil, compressionName: nil, compressionPools: [:], codec: ProtoCodec(), interceptors: [] ) @@ -35,7 +35,7 @@ final class ProtocolClientConfigTests: XCTestCase { func testGzipRequestOptionUsesGzipCompressionPool() { var config = ProtocolClientConfig( - target: "https://buf.build", httpClient: URLSessionHTTPClient(), + host: "https://buf.build", httpClient: URLSessionHTTPClient(), compressionMinBytes: nil, compressionName: nil, compressionPools: [:], codec: ProtoCodec(), interceptors: [] ) @@ -65,7 +65,7 @@ final class ProtocolClientConfigTests: XCTestCase { final class InterceptorB: NoopInterceptor {} var config = ProtocolClientConfig( - target: "https://buf.build", httpClient: URLSessionHTTPClient(), + host: "https://buf.build", httpClient: URLSessionHTTPClient(), compressionMinBytes: nil, compressionName: nil, compressionPools: [:], codec: ProtoCodec(), interceptors: [] ) @@ -79,7 +79,7 @@ final class ProtocolClientConfigTests: XCTestCase { func testJSONClientOptionSetsJSONCodec() { var config = ProtocolClientConfig( - target: "https://buf.build", httpClient: URLSessionHTTPClient(), + host: "https://buf.build", httpClient: URLSessionHTTPClient(), compressionMinBytes: nil, compressionName: nil, compressionPools: [:], codec: ProtoCodec(), interceptors: [] ) @@ -89,7 +89,7 @@ final class ProtocolClientConfigTests: XCTestCase { func testProtoClientOptionSetsProtoCodec() { var config = ProtocolClientConfig( - target: "https://buf.build", httpClient: URLSessionHTTPClient(), + host: "https://buf.build", httpClient: URLSessionHTTPClient(), compressionMinBytes: nil, compressionName: nil, compressionPools: [:], codec: JSONCodec(), interceptors: [] )