Skip to content

Commit

Permalink
Fix ':scheme' for posix client (grpc#1972)
Browse files Browse the repository at this point in the history
Motivation:

The client doesn't support TLS (yet) but uses the 'https' scheme.

Modifications:

- Use the correct scheme
- Add tests

Result:

Fewer bugs
  • Loading branch information
glbrntt committed Jul 8, 2024
1 parent 595a416 commit 951b4d3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 144,7 @@ extension HTTP2ClientTransport.Posix {
}
}

return HTTP2Connection(channel: channel, multiplexer: multiplexer, isPlaintext: false)
return HTTP2Connection(channel: channel, multiplexer: multiplexer, isPlaintext: true)
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions Tests/GRPCHTTP2TransportTests/HTTP2TransportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 1353,62 @@ final class HTTP2TransportTests: XCTestCase {
}
}
}

func testUnaryScheme() async throws {
try await self.forEachTransportPair { control, pair in
let input = ControlInput.with {
$0.echoMetadataInHeaders = true
$0.numberOfMessages = 1
}
let request = ClientRequest.Single(message: input)
try await control.unary(request: request) { response in
XCTAssertEqual(Array(response.metadata["echo-scheme"]), ["http"])
}
}
}

func testServerStreamingScheme() async throws {
try await self.forEachTransportPair { control, pair in
let input = ControlInput.with {
$0.echoMetadataInHeaders = true
$0.numberOfMessages = 1
}
let request = ClientRequest.Single(message: input)
try await control.serverStream(request: request) { response in
XCTAssertEqual(Array(response.metadata["echo-scheme"]), ["http"])
}
}
}

func testClientStreamingScheme() async throws {
try await self.forEachTransportPair { control, pair in
let request = ClientRequest.Stream(of: ControlInput.self) { writer in
let input = ControlInput.with {
$0.echoMetadataInHeaders = true
$0.numberOfMessages = 1
}
try await writer.write(input)
}
try await control.clientStream(request: request) { response in
XCTAssertEqual(Array(response.metadata["echo-scheme"]), ["http"])
}
}
}

func testBidiStreamingScheme() async throws {
try await self.forEachTransportPair { control, pair in
let request = ClientRequest.Stream(of: ControlInput.self) { writer in
let input = ControlInput.with {
$0.echoMetadataInHeaders = true
$0.numberOfMessages = 1
}
try await writer.write(input)
}
try await control.bidiStream(request: request) { response in
XCTAssertEqual(Array(response.metadata["echo-scheme"]), ["http"])
}
}
}
}

@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
Expand Down

0 comments on commit 951b4d3

Please sign in to comment.