25 Commits

Author SHA1 Message Date
George Barnett
0447b0359e
Strict concurrency for NIOHTTPCompression (#257) 2025-04-01 15:29:54 +01:00
Rick Newton-Rogers
3f776e9aaf
Migrate CI to use GitHub Actions. (#234)
### Motivation:

To migrate to GitHub actions and centralised infrastructure.

### Modifications:

Changes of note:
* Adopt swift-format using rules from SwiftNIO
* Remove scripts and docker files which are no longer needed

### Result:

Feature parity with old CI.
2024-10-28 14:00:57 +00:00
Dimitri Bouniol
d1ead62745
Conditional Response Compression (#225)
* Added support for conditional response compression

* Updated expectations to be fulfilled via a defer

* Updated compression response predicate to return an intent enum rather than a boolean
2024-07-18 16:19:20 +01:00
David Nadoba
8b9030df7c
Enable automatic compression format detection (#208)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-03-26 02:57:29 -07:00
Iceman
3bbec9883a
Fix NIOHTTPDecompression bug for multi-request channels (#221)
Motivation:

`NIOHTTPDecompression` erroneously accumulates decompressed data sizes across multiple requests in a single channel, leading to unwarranted `DecompressionError.limit` errors. This affects applications using persistent connections, as the decompression limits are improperly enforced. This change aims to address and rectify this issue.

Modifications:

- Add initialization of `inflated` within `Decompressor.initializeDecoder`.
- Introduced new tests to validate decompression functionality across multiple requests on the same channel

Result:

This fix ensures each request's decompression size is independently considered, eliminating incorrect limit errors, and enhancing reliability for applications using HTTP compression with persistent connections.
2024-03-20 01:58:49 -07:00
Cory Benfield
9cdb93e321
Drop Swift 5.5 (#197)
Motivation

Per SwiftNIO's formal version policy, we are ready to drop support for
Swift 5.5.

Modifications

This patch removes the support for 5.5 and all supporting
infrastructure. This includes the test generation functionality, which
is no longer required, as well as the files generated by that
functionality. It updates the dockerfile for 5.8, and it removes all
conditional compilation checks that are now definitionally true.

Result

A nice, clean, 5.6+ codebase
2023-04-13 16:47:28 +01:00
David Nadoba
d373eaf7db
Replace NIOSendable with Sendable (#181) 2022-10-13 07:43:15 -07:00
Cory Benfield
6c84d24775
Correctly validate the bounds of decompression (#177)
Motivation

Currently we don't confirm that the decompression has completed
successfully. This means that we can incorrectly spin forever attempting
to decompress past the end of a message, and that we can fail to notice
that a message is truncated. Neither of these is good.

Modifications

Propagate the message zlib gives us as to whether or not decompression
is done, and keep track of it.
Add some tests written by @vojtarylko to validate the behaviour.

Result

Correctly police the bounds of the messages.
Resolves #175 and #176.
2022-09-16 08:22:42 +01:00
David Nadoba
1ef46c0352
Adopt Sendable in NIOHTTPCompression (#172) 2022-08-23 13:24:16 +01:00
Peter Adams
dabef818d3
Simple index pages for docc (#170)
Motivation:

An index page ties all the other documentation together

Modifications:

Add index pages for the library targets.
Correct a few minor errors in the main docs.

Result:

A more joined up documentation experience.
2022-08-12 07:31:17 -07:00
Peter Adams
da7c04777b
Docnioextras (#169)
* Improve documentation for NIOExtras

Motivation:

Docs will help users do things correctly.

Modifications:

Add missing comments, improve links.

Result:

Better docc documentation

* Docc in NIOHTTPCompression

* NIOSOCKS docc

* Correct bad symbol

* Minor typo

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-08-03 01:34:45 -07:00
Cory Benfield
d66ae0557e
Clean up imports and dependencies. (#144)
Motivation:

With NIO 2.32.0 we broke the core NIO module up into modules that split
apart the POSIX layer and the core abstractions. As a result, this
package no longer needs to express a hard dependency on the POSIX layer.

Modifications:

- Rewrote imports of NIO to NIOCore.
- Added NIOEmbedded and NIOPosix imports where necessary in tests.
- Extended soundness script to detect NIO imports.
- Note that the main modules still depend on NIO, which is necessary
    for backwards-compatibility reasons. This dependency is unused.

Result:

No need to use NIOPosix.
2021-09-14 16:30:39 +01:00
Tanner
0b9eb87b22
Skip HTTPResponseCompressor logic if response is 204 (no content) (#105)
* Skip HTTPResponseCompressor logic if response is 204 (no content)

* update test manifests

* use mayHaveResponseBody
2020-08-14 17:10:00 +01:00
Karl
f700f5b355
Rename startsWithSameUnicodeScalars -> startsWithExactly, switch to comparing UTF8 bytes. (#104) 2020-08-05 10:47:25 +01:00
gkaindl
d525d3bbd1
Ensures gzip/deflate-compressed responses are properly finalized in all cases (#100)
Motivation:

Previously, when using the response compressor, doing a flush() right before finishing the
response data would cause the final compression chunk to be omitted. Some strict decompressors
(such as gzip or the zlib functionality exported in nodejs) would refuse to decompress the
incomplete response.

With this change, the generated compressed response is properly finalized.

Modifications:

In HTTPResponseCompressor.swift, a channel write is now also generated if no body data is
added, but a flush is required.

Result:

The response is now correct for this edge case, enabling gzip, nodejs, et al., to
decompress it without errors.
2020-07-28 17:33:35 +01:00
Fabian Fett
b8fd38c1db
Support decompression of HTTP responses that do not contain a Content… (#93)
Fixes #78

Co-authored-by: Trevör Anne Denise <trevor.annedenise@icloud.com>
2020-07-24 11:12:09 +01:00
Trevör
f21a87da13
Merge pull request from GHSA-xhhr-p2r9-jmm7
Motivation:
NIOHTTPRequestDecompressor and HTTPResponseDecompressor are both affected by an issue where the decompression limits defined by their DecompressionLimit property wasn't correctly checked when is was set with DecompressionLimit.size(...), allowing denial of service attacks.

Modifications:
- Update DecompressionLimit.size(...) to correctly check the size of the decompressed data.
- Update test cases to avoid future regressions regarding the size checks.

Result:
Prevents DoS attacks though maliciously crafted compressed data.
2020-05-02 09:29:33 +01:00
Adam Fowler
020e322a65
Added NIOHTTPRequestCompressor to compress requests (#88)
* Added NIOHTTPRequestCompressor to compress requests

Also moved common code from request and response compressor into separate NIOHTTPCompression enum.

* Updates after comments from @weissi

Also reinstated public enum HTTPResponseCompressor.CompressionError

* algorithms are now let not var

* Catch situation where head is flushed before anything else comes through

Content-encoding was not being set
Added additional tests for header values

* Added documentation around 5 bytes added to buffer size and add them

* Renaming NIOHTTPCompressionSetting to NIOCompression

Also
NIOHTTPCompressionSetting.CompressionAlgorithm is NIOCompression.Algorithm
NIOHTTPCompressionSetting.CompressionError is NIOCompression.Error
Algorithm now conforms to Equatable

* Forgot to run generate_linux_tests

* Fix typos
2020-04-30 17:28:49 +01:00
Artem Redkin
ed97628fa3 fix NIO 2.9.0 deprecations (#61)
Motivation:

Usage of deprecated methods is bad.

Modification:

Fix usage of deprecated methods.

Result:

Fewer warnings.
2019-10-23 17:23:34 -07:00
Caleb Kleveter
0584020dca Gzip request decompress (#59)
### Motivation:

There will be times when a client wishes to send larger requests with gzipped bodies to save on network traffic. This PR adds a `NIOHTTPRequestDecompressor` which can be added to the server's channel pipeline so those requests are automatically inflated.

### Modifications:

- Added a `CNIOExtrasZlib_voidPtr_to_BytefPtr` C method.
- Added a `NIOHTTPRequestDecompressor` type.
- Added a `HTTPResponseDecompressorTest` test case.

### Result:

Now you don't have to manually check the `Content-Encoding` header and decompress the body on each incoming request.
2019-10-10 13:51:07 +01:00
Artem Redkin
16fbdf3868 extract common classes for server request decompressor (#60)
* extract common classes for server request decompressor

* review fix: make fields private and make state part of the handler

* review fixes

* review fix: reserve capacity before inflating
2019-10-08 12:23:32 +01:00
Artem Redkin
863c6b55c6 add http client decompressor (#56)
### Motivation:
Many HTTP servers can send compressed responses to clients and it would be a great feature for `AsyncHTTPClient` to support it. But since we want to minizime usage of unsafe APIs in SSWG projects, I propose to consolidate interfacing with zlib to `nio-extras` since it already supports `zlib` compression.

### Modifications:
Added `HTTPResponseDecompressor` and accompanying tests

### Result:
Users (primarily `AsyncHTTPClient`) can now provide automatic response decompression support.
2019-10-02 15:39:46 +01:00
Johannes Weiss
5b67140545
make HTTPResponseCompressor removable (#33)
Motivation:

HTTPResponseCompressor is trivially removable, so mark it.

Modifications:

make HTTPResponseCompressor implement RemovableChannelHandler

Result:

HTTPResponseCompressor can be removed
2019-03-08 18:32:08 +00:00
Johannes Weiss
b972d1b03d
update to latest NIO (#36)
Motivation:

code needs to compile to be good

Modifications:

make code compile

Result:

code compiles
2019-03-08 18:10:54 +00:00
Johannes Weiss
7a3e42a40f
move HTTPResponseDecoder to swift-nio-extras (#28)
Motivation:

HTTPResponseDecoder needs to incumbate, so move to nio-extras.

Modifications:

move all the code here.

Result:

incubation can begin
2019-03-05 17:59:29 +00:00