Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using package level API from CompressionAlgorithm #69

Merged
merged 2 commits into from
Feb 3, 2025
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 @@ -34,14 +34,16 @@ extension CompressionAlgorithm {
}
}

var name: String {
switch self.value {
case .gzip:
/// The name of the algorithm, if supported.
var nameIfSupported: String? {
if self == .gzip {
return "gzip"
case .deflate:
} else if self == .deflate {
return "deflate"
case .none:
} else if self == .none {
return "identity"
} else {
return nil
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions Sources/GRPCNIOTransportCore/GRPCStreamStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,14 @@ extension GRPCStreamStateMachine {
headers.add(ContentType.grpc.canonicalValue, forKey: .contentType)
headers.add("trailers", forKey: .te) // Used to detect incompatible proxies

if let encoding = outboundEncoding, encoding != .none {
headers.add(encoding.name, forKey: .encoding)
if let encoding = outboundEncoding, encoding != .none, let name = encoding.nameIfSupported {
headers.add(name, forKey: .encoding)
}

for encoding in acceptedEncodings.elements.filter({ $0 != .none }) {
headers.add(encoding.name, forKey: .acceptEncoding)
for encoding in acceptedEncodings.elements where encoding != .none {
if let name = encoding.nameIfSupported {
headers.add(name, forKey: .acceptEncoding)
}
}

for metadataPair in customMetadata {
Expand Down Expand Up @@ -1239,7 +1241,7 @@ extension GRPCStreamStateMachine {
extension GRPCStreamStateMachine {
private func formResponseHeaders(
in headers: inout HPACKHeaders,
outboundEncoding: CompressionAlgorithm?,
outboundEncoding encoding: CompressionAlgorithm?,
configuration: GRPCStreamStateMachineConfiguration.ServerConfiguration,
customMetadata: Metadata
) {
Expand All @@ -1252,8 +1254,8 @@ extension GRPCStreamStateMachine {
headers.add("200", forKey: .status)
headers.add(ContentType.grpc.canonicalValue, forKey: .contentType)

if let outboundEncoding, outboundEncoding != .none {
headers.add(outboundEncoding.name, forKey: .encoding)
if let encoding, encoding != .none, let name = encoding.nameIfSupported {
headers.add(name, forKey: .encoding)
}

for metadataPair in customMetadata {
Expand Down Expand Up @@ -1495,7 +1497,9 @@ extension GRPCStreamStateMachine {
)

for acceptedEncoding in configuration.acceptedEncodings.elements {
trailers.add(name: GRPCHTTP2Keys.acceptEncoding.rawValue, value: acceptedEncoding.name)
if let name = acceptedEncoding.nameIfSupported {
trailers.add(name: GRPCHTTP2Keys.acceptEncoding.rawValue, value: name)
}
}

return .rejectRPC_serverOnly(trailers: trailers)
Expand Down
Loading