Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension ConnectInterceptor: Interceptor {
}

return HTTPRequest(
target: request.target,
url: request.url,
contentType: request.contentType,
headers: headers,
message: finalRequestBody
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
24 changes: 12 additions & 12 deletions Libraries/Connect/Implementation/ProtocolClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Connect/Implementation/ProtocolClientConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Libraries/Connect/Interfaces/HTTPRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ 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.
public let headers: Headers
/// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ 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(),
GzipRequestOption(compressionMinBytes: 10),
GzipCompressionOption()
)
self.connectProtoClient = ProtocolClient(
target: target,
host: host,
httpClient: httpClient,
ConnectClientOption(),
ProtoClientOption(),
GzipRequestOption(compressionMinBytes: 10),
GzipCompressionOption()
)
self.grpcWebJSONClient = ProtocolClient(
target: target,
host: host,
httpClient: httpClient,
GRPCWebClientOption(),
JSONClientOption(),
GzipRequestOption(compressionMinBytes: 10),
GzipCompressionOption()
)
self.grpcWebProtoClient = ProtocolClient(
target: target,
host: host,
httpClient: httpClient,
GRPCWebClientOption(),
ProtoClientOption(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: []
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
)
Expand All @@ -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: []
)
Expand Down Expand Up @@ -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: []
)
Expand All @@ -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: []
)
Expand All @@ -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: []
)
Expand Down