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

Add HTTPResponseCompressor intent for cases where requested compression algorithm is not supported #228

Closed
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
6 changes: 5 additions & 1 deletion Sources/NIOHTTPCompression/HTTPResponseCompressor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public final class HTTPResponseCompressor: ChannelDuplexHandler, RemovableChanne
///
/// - Parameter responseHeaders: The headers that will be used for the response. These can be modified as needed at this stage, to clean up any marker headers used to statelessly determine if compression should occur, and the new headers will be used when writing the response. Compression headers are not yet provided and should not be set; ``HTTPResponseCompressor`` will set them accordingly based on the result of this predicate.
/// - Parameter isCompressionSupported: Set to `true` if the client requested compatible compression, and if the HTTP response supports it, otherwise `false`.
/// - Returns: Return ``CompressionIntent/compressIfPossible`` if the compressor should proceed to compress the response, or ``CompressionIntent/doNotCompress`` if the response should not be compressed.
/// - Returns: Return ``CompressionIntent/compressIfPossible`` if the compressor should proceed to compress the response, or ``CompressionIntent/doNotCompressWithUnsupportedAlgorithm`` if the response should not be compressed due to the unsupported algorithm, or ``CompressionIntent/doNotCompress`` if the response should not be compressed.
///
/// - Note: Returning ``CompressionIntent/compressIfPossible`` is only a suggestion — when compression is not supported, the response will be returned as is along with any modified headers.
public typealias ResponseCompressionPredicate = (
Expand All @@ -92,6 +92,8 @@ public final class HTTPResponseCompressor: ChannelDuplexHandler, RemovableChanne
enum RawValue {
/// The response should be compressed if supported by the HTTP protocol.
case compressIfPossible
/// The response should not be compressed because the requested compression algorithm is not supported.
case doNotCompressWithUnsupportedAlgorithm
/// The response should not be compressed even if supported by the HTTP protocol.
case doNotCompress
}
Expand All @@ -106,6 +108,8 @@ public final class HTTPResponseCompressor: ChannelDuplexHandler, RemovableChanne

/// The response should be compressed if supported by the HTTP protocol.
public static let compressIfPossible = CompressionIntent(.compressIfPossible)
/// The response should not be compressed because the requested compression algorithm is not supported.
public static let doNotCompressWithUnsupportedAlgorithm = CompressionIntent(.doNotCompressWithUnsupportedAlgorithm)
/// The response should not be compressed even if supported by the HTTP protocol.
public static let doNotCompress = CompressionIntent(.doNotCompress)
}
Expand Down