Skip to content

Commit

Permalink
2.x.x request decompression, response compression middleware (#10)
Browse files Browse the repository at this point in the history
* Comment everything out, sort Package.swift

* HBRequestDecompressionMiddleware

* Request decompression middleware

* ResponseCompressionMiddleware

* Renaming, moving code about

* Response compression headers

* Added configuration to middleware

* Remove old files

* Verify compression window sizes

* Update CI

* Use compress-nio 1.2.1

* Use deflate in some of the tests

* Update README

* Changes from PR comments

* Throw badRequest on corrupt data

* Add another bad data test

* Print error to logger when inflate/deflate init/finish fails

It should never fail, but if it does we have some output

* Fix test, we need to check contentEncoding header
  • Loading branch information
adam-fowler authored May 14, 2024
1 parent 50d9593 commit acd628c
Show file tree
Hide file tree
Showing 11 changed files with 628 additions and 898 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ jobs:
strategy:
matrix:
image:
- 'swift:5.6'
- 'swift:5.7'
- 'swift:5.8'
- 'swift:5.9'
- 'swift:5.10'

container:
image: ${{ matrix.image }}
Expand Down
12 changes: 5 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
// swift-tools-version:5.5
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "hummingbird-compression",
platforms: [.iOS(.v12), .tvOS(.v12)],
platforms: [.macOS(.v14), .iOS(.v17), .tvOS(.v17)],
products: [
.library(name: "HummingbirdCompression", targets: ["HummingbirdCompression"]),
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "1.0.0"),
.package(url: "https://github.com/adam-fowler/compress-nio.git", from: "1.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", branch: "main"),
.package(url: "https://github.com/adam-fowler/compress-nio.git", from: "1.2.1"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.1"),
],
targets: [
.target(name: "HummingbirdCompression", dependencies: [
.product(name: "Hummingbird", package: "hummingbird"),
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "CompressNIO", package: "compress-nio"),
]),
.testTarget(name: "HummingbirdCompressionTests", dependencies: [
.byName(name: "HummingbirdCompression"),
.product(name: "HummingbirdXCT", package: "hummingbird"),
.product(name: "HummingbirdTesting", package: "hummingbird"),
]),
]
)
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ Adds request decompression and response compression to Hummingbird
## Usage

```swift
let app = HBApplication()
// run response compression on application thread pool when buffer is
// larger than 32768 bytes otherwise run it on the eventloop
app.addResponseCompression(execute: .onThreadPool(threshold: 32768))
// run request decompression on eventloop with no limit to the size
// of data that can be decompressed
app.addRequestDecompression(execute: .onEventLoop, limit: .none)
let router = Router()
router.middlewares.add(RequestDecompressionMiddleware())
router.middlewares.add(ResponseCompressionMiddleware(minimumResponseSizeToCompress: 512))
```

Adding request decompression means when a request comes in with header `content-encoding` set to `gzip` or `deflate` the server will attempt to decompress the request body. Adding response compression means when a request comes in with header `accept-encoding` set to `gzip` or `deflate` the server will compression the response body.
Adding request decompression middleware means when a request comes in with header `content-encoding` set to `gzip` or `deflate` the server will attempt to decompress the request body. Adding response compression means when a request comes in with header `accept-encoding` set to `gzip` or `deflate` the server will compression the response body.
58 changes: 0 additions & 58 deletions Sources/HummingbirdCompression/Application+Compression.swift

This file was deleted.

36 changes: 0 additions & 36 deletions Sources/HummingbirdCompression/HTTPServer+Compression.swift

This file was deleted.

221 changes: 0 additions & 221 deletions Sources/HummingbirdCompression/RequestDecompression.swift

This file was deleted.

Loading

0 comments on commit acd628c

Please sign in to comment.