103 Commits

Author SHA1 Message Date
Marc Prud'hommeaux
8526b90bc4
Ignore return value of signal() on Android (#266)
See https://github.com/apple/swift-nio/pull/3181 and
https://github.com/apple/swift-nio/issues/3180
2025-04-09 13:16:39 +00:00
George Barnett
a0189d045c
Strict concurrency for NIOResumableUpload (#265)
HTTPResumableUpload contains the core logic. It uses an event loop to
synchronize its state internally. Some methods are safe to call from off
of that event loop and have been moved to a new sendable view. The
HTTPResumableUpload type is marked as explicitly not sendable.

As such, most other types now hold on to the sendable view and use that
as the interface to HTTPResumableUpload.

HTTPResumableUploadChannel must be sendable (it's a Channel) and now
uses safe abstractions (where possible).
2025-04-08 09:21:01 +01:00
George Barnett
b6b5e1133f
Strict concurrency for NIONFS3 and NIONFS3Tests (#264) 2025-04-07 15:09:17 +01:00
George Barnett
cf3de22478
Strict concurrency for NIOExtrasPerformanceTester (#263) 2025-04-02 12:26:48 +00:00
George Barnett
1a16877a1b
Strict concurrency for HTTPServerWithQuiescingDemo (#262) 2025-04-02 13:20:46 +01:00
George Barnett
c92af9d4ef
Strict concurrency for HTTPTypes and friends (#259) 2025-04-01 15:44:08 +00:00
George Barnett
7241067079
Strict concurrency for NIOHTTPResponsiveness and NIOHTTPResponsivenessTests (#261) 2025-04-01 15:32:33 +00:00
George Barnett
dc6987e77e
Strict concurrency for NIOSOCKS (#256) 2025-04-01 14:33:46 +00:00
George Barnett
0447b0359e
Strict concurrency for NIOHTTPCompression (#257) 2025-04-01 15:29:54 +01:00
George Barnett
20c59b2d64
Strict concurrency for NIOExtras and NIOExtrasTests (#254) 2025-03-31 11:53:06 +01:00
Guoye Zhang
00f3f72d2f
Eliminate hasPrefix usage for pseudo HTTP header names (#248)
UTF8 view is faster than hasPrefix

rdar://144395951
2025-02-15 18:14:17 -08:00
Rick Newton-Rogers
926c3e19e7
Avoid integer overrun in NIOHTTPResponsiveness (#247)
We use 8*10^9 in `NIOHTTPResponsiveness` however this number will
overrun the integer size on platforms with 32-bit pointer-width such as
watchOS.

This change drops down to use 1*10^9 on such platforms.
2025-01-31 16:00:41 +00:00
Eric Rosenberg
4804de1953
Responsiveness under Working Conditions (#242)
Implementation of
https://datatracker.ietf.org/doc/draft-ietf-ippm-responsiveness/ (draft
5) with flexible download and upload handlers to suit other use cases as
well.

### Motivation:

The provided handlers are useful for measuring responsiveness and
testing things like performance of proxies

### Modifications:

Add `NIOHTTPResponsiveness` and `NIOHTTPResponsivenessServer`

### Result:

We'll now have an implementation of the Responsiveness under Working
Conditions draft

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-01-21 17:14:26 +00:00
Marc Prud'hommeaux
aa0d902637
Android support (#244)
Add Android support

### Motivation:

Support the Android platform.

### Modifications:

Add Android imports and fix the default temporary directory to be
correct for the OS.

### Result:

The package will build and test on Android.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-01-14 16:48:42 +00:00
George Barnett
74a143a79f
Fix warnings (#245)
Motivation:

The latest NIO release deprecated a number of APIs and added more
Sendable contraints.

Modifications:

- Use sync APIs where possible
- Use `_deprecated` but not `@deprecated` NIOFileHandle API
- Stop using NIOAny

Result:

No warnings
2025-01-14 11:24:08 +00:00
Eric Rosenberg
066c8e4ccd
support h2 stream resets through user events (#241)
Allow applications to trigger HTTP/2 stream resets while using
NIOHTTPTypesHTTP2's codecs

### Motivation:

Resetting streams with specific error codes is required by some
applications such as those implementing the CONNECT method
(see https://datatracker.ietf.org/doc/html/rfc9113#section-8.5-8).
Unfortunately, the HTTP2ToHTTP codecs don't expose this capability to
applications.

### Modifications:

Introduce an outbound user event applications can trigger when needing
to reset an HTTP/2 stream.

### Result:

Now applications can trigger HTTP/2 stream resets while using the codecs
provided by NIOHTTPTypesHTTP2
2025-01-07 08:05:05 +00:00
Rick Newton-Rogers
5c7978016e
Enable MemberImportVisibility check on all targets (#240)
Enable MemberImportVisibility check on all targets. Use a standard
string header and footer to bracket the new block for ease of updating
in the future with scripts.
2024-12-13 15:07:05 +01:00
Guoye Zhang
fde9d65d2e
Import HTTP resumable upload sample code (#203)
Support HTTP resumable upload.

### Motivation:

Supporting HTTP resumable upload protocol defined in
https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-resumable-upload-05

* Interop version 3: iOS 17.0, macOS 14.0
* Interop version 5: iOS 18.0, macOS 15.0
* Interop version 6: iOS 18.1, macOS 15.1

### Modifications:

2 new public classes, `HTTPResumableUploadHandler` and
`HTTPResumableUploadContext`, and a few other supporting objects to
manage resumable uploads and translate them into regular uploads.

---------

Co-authored-by: Jonathan Flat <jflat@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-12-11 07:39:13 +00: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
Rick Newton-Rogers
4f888611eb
LineBasedFrameDecoder.decodeLast handle more frames (#229)
### Motivation:

`LineBasedFrameDecoder.decodeLast` throws an error if there is more than
one frame’s worth of bytes remaining in the buffer.

This is in violation of the `NIOSingleStepByteToMessageDecoder`protocol
requirement that this method be called in a loop until all bytes are
decoded.

### Modifications:

* The method now only throws if the decode operation could not return a
frame and there are bytes left in the buffer (previously only the latter
criterion applied).
* Method documentation is updated.
* Test added.

### Result:

`LineBasedFrameDecoder.decodeLast` can cope with more edge cases.

Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2024-09-11 16:44:42 +01: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
Joannis Orlandos
ef36e67dbb
Use oldHeaders.count when reserving capacity in HTTPFields (#223) 2024-05-20 05:05:55 -07: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
Hovik Melikyan
c992030a2d
Fixed the shutdown order for quiescing demo (#220) 2024-03-18 01:11:05 -07:00
Adam Fowler
a3b640d7dc
Make HTTP type conversion code public (#216)
* Make HTTP1 type conversion code public

* Convert HTTP1TypeConversionError to struct

---------

Co-authored-by: Franz Busch <f.busch@apple.com>
2024-02-12 02:25:12 -08:00
Johannes Weiss
cdd1580a03
LineBasedFrameDecoder: can be a NIOSingleStepByteToMessageDecoder (#217)
Co-authored-by: Johannes Weiss <johannes@jweiss.io>
2024-02-06 16:31:09 +00:00
Adam Fowler
6717fd068f
Add RemovableChannelHandler comformance to HTTPType channel handlers (#213) 2023-12-06 10:00:50 +00:00
Alastair Houghton
373b8bba29
Changes for Musl support. (#211)
Make sure we import `Musl` rather than `Glibc`.
2023-11-28 08:38:46 -08:00
George Barnett
df34965cd7
Don't reserve capacity for NIOPCAPRingBuffer (#209)
Motivation:

The NIOPCAPRingBuffer can limit the number of fragment or the total
number of bytes in its buffer or both. When configuring the buffer to
limit only the maximum number of bytes it sets the maximum number of
fragments allowed to `.max`. On `init` the buffer has enough capacity
reserved to store tha maximum number of fragments.

This would be a large and potentially totally unnecessary allocation.
That is, if it didn't crash at runtime. It crashes at runtime as
`CircularBuffer` converts the requested capacity to a `UInt32` which
traps if you pass it an `Int.max`.

Modifications:

- Don't reserve capacity on init
- Adjust the test which tests the byte limit to not set a capacity as
  well

Result:

- `NIOPCAPRingBuffer(maximumBytes:)` doesn't crash
2023-11-03 10:04:31 +00:00
Guoye Zhang
798c962495
Add HTTP types adapter for SwiftNIO (#202)
* Add HTTP types adapter for SwiftNIO

* swiftformat

* Guard on Swift 5.8

* Review comments

* Update swift-http-types to 0.1.1

* Update swift-http-types to 1.0.0

* Review feedback

* Review feedback

* Bump minimum Swift version to 5.7.1

* Allow Host in any order
2023-10-20 17:55:23 +01:00
Rick Newton-Rogers
6c3819cf2a
Bump minimum Swift version to 5.7 (#207)
Motivation:

Now that Swift 5.9 is GM we should update the supported versions and
remove 5.6

Modifications:

* Update `Package.swift`
* Remove `#if swift(>=5.7)` guards
* Delete the 5.6 docker compose file and make a 5.10 one
* Update docs

Result:

Remove support for Swift 5.6, add 5.10
2023-10-04 10:17:34 +01:00
Franz Busch
fb70a0f5e9
Use #if canImport(Darwin) where possible (#201) 2023-06-21 14:12:47 +01: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
Cory Benfield
0e0d0aab66
Fix documentation and add support for CI-ing it (#196)
* Fix documentation and add support for CI-ing it

* Soundness cleanup
2023-04-11 11:25:17 +01:00
Johannes Weiss
df2810507b
TaggedRequestResponseHandler (#157) 2023-03-22 13:02:05 +00:00
Johannes Weiss
4569c6911b
add the NFS3 protocol (#155)
* add the NFS3 protocol

* make writes return the amount of bytes written

* nits, docs, removes

* compiler errors on old swifts

* Hashable everything

* delay errors

* remove typealiases

* Sendables

* implicit endiannes

* more changes
2023-03-21 17:10:58 +00:00
Cory Benfield
cc1e527507
Make SynchronizedFileSink.close unavailable from async (#195)
Motivation

syncClose will block whatever thread it's on indefinitely. That makes it
unsafe to call in async contexts.

Modifications

Add a new close() method that's async.
Make the existing method unavailable from async.
Add some tests.

Results

Easier to close these from async contexts
2023-03-03 05:48:20 -08:00
Franz Busch
d75ed708d0
Refactor QuiescingHelper to exhaustively iterate state (#193)
# Motivation
Currently the `QuiescingHelper` is crashing on a precondition if you call shutdown when it already was shutdown. However, that can totally happen and we should support it.

# Modification
Refactor the `QuiescingHelper` to exhaustively switch over its state in every method. Furthermore, I added a few more test cases to test realistic scenarios.

# Result
We are now reliable checking our state and making sure to allow most transitions.
2023-02-24 09:24:37 -08:00
carolinacass
6bd9bf5c29
ServerQuiescingHelper no longer leaking promises (#192)
* ServerQuiescingHelper no longer leaking promises

Motivation:
ServerQuiescingHelper leaked promises when promise left scope and not succeeded

Modifications:
Failing promise within a deinit

* Minor fixes

* generating linux tests

* mini update
2023-02-13 11:45:10 +00:00
Rick Newton-Rogers
5ff8cc59a6
Migrate http1 proxy connect handler (#185)
Motivation:

Moving the HTTP1ProxyConnectHandler into swift-nio-extras will make the
code which is generally useful when dealing with HTTP1 proxies available
more easily to a wider audience.

Modifications:

The code and tests are copied over from 0b5bec741b/Sources/AsyncHTTPClient/ConnectionPool/ChannelHandler/HTTP1ProxyConnectHandler.swift.

Result:

HTTP1ProxyConnectHandler will be surfaced via the NIOExtras library
2023-01-12 13:56:04 +00:00
David Nadoba
d373eaf7db
Replace NIOSendable with Sendable (#181) 2022-10-13 07:43:15 -07:00
David Nadoba
985a485f71
Remove #if compiler(>=5.5) (#182) 2022-10-13 14:04:27 +01: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
5334d949fe
Adopt Sendable in NIOExtras (#174)
Incremental `Sendable` adoption.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-08-23 15:20:41 +01:00
David Nadoba
b64e59956e
Adopt Sendable in NIOSOCKS (#173)
Incremental `Sendable` adoption.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-08-23 05:28:01 -07: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
Peter Adams
ca22c12528
Deprecate cumulationBuffer (#168)
Motivation:

It is no longer used.

Modifications:

Deprecate the 3 cumulationBuffers

Result:

Less confusion and accidental usage.
2022-08-02 09:46:57 +01:00