Skip to content

Commit

Permalink
HTTP2 Response Compression/Request Decompression (#3126)
Browse files Browse the repository at this point in the history
* Fixed an issue where HTTP2 didn't support response compression and request recompression

Fixes #3125

* Added exhaustive tests for request and response compression across both HTTP 1.1 and HTTP 2
  • Loading branch information
dimitribouniol committed Apr 19, 2024
1 parent 096c519 commit 71dff4f
Show file tree
Hide file tree
Showing 2 changed files with 383 additions and 3 deletions.
22 changes: 22 additions & 0 deletions Sources/Vapor/HTTP/Server/HTTPServer.swift
Expand Up @@ -503,6 +503,28 @@ extension ChannelPipeline {
let http2 = HTTP2FramePayloadToHTTP1ServerCodec()
handlers.append(http2)

/// Add response compressor if configured.
switch configuration.responseCompression.storage {
case .enabled(let initialByteBufferCapacity):
let responseCompressionHandler = HTTPResponseCompressor(
initialByteBufferCapacity: initialByteBufferCapacity
)
handlers.append(responseCompressionHandler)
case .disabled:
break
}

/// Add request decompressor if configured.
switch configuration.requestDecompression.storage {
case .enabled(let limit):
let requestDecompressionHandler = NIOHTTPRequestDecompressor(
limit: limit
)
handlers.append(requestDecompressionHandler)
case .disabled:
break
}

/// Add NIO → HTTP request decoder.
let serverReqDecoder = HTTPServerRequestDecoder(
application: application
Expand Down

0 comments on commit 71dff4f

Please sign in to comment.