Commit Graph

69 Commits

Author SHA1 Message Date
Fabian Fett 5844a6b4ee Crash fix: HTTP2 can handle requests are cancelled (#555)
Co-authored-by: George Barnett <gbarnett@apple.com>
2022-02-10 10:42:27 +01:00
Fabian Fett ce3958ff92 Fix race between connection close and scheduling new request (#546) 2022-01-24 12:07:41 +00:00
Fabian Fett 2497a68427 Print invalid state, if hitting precondition (#545) 2022-01-24 12:26:08 +01:00
David Nadoba c2805dfa4e Prepare async/await API for public release (#531) 2022-01-14 14:35:17 +01:00
David Nadoba e531961906 remove dot from HTTP1.1 folder (#535)
Swift tools version 5.3 and higher (the version that is specified at very top of a Package.swift file) excludes folders with a dot in the name by default. It luckily produces a warning "found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target". However, this issue is buried under a lot of missing types Errors because of the 3 excluded files.
I run into this issue and it took me some time to figure out what the actual problem was. As we will eventually move from 5.2 to 5.3 we can already save the next person some time by resolving this issue now.
2021-12-23 00:09:38 +01:00
David Nadoba e4b11eb547 Fix HTTP1 to HTTP2 migration while shutdown is in progress (#530)
* Fix HTTP1 to HTTP2 migration while shutdown is in progress

### Motivation
Calling `HTTPClient.shutdown()` may never return if connections are still starting and one new established connection results in a state migration (i.e. from HTTP1 to HTTP2 or vice versa). We forgot to migrate the shutdown state. This could result in a large dealy until `.shutdown()` returns because we wait until connections are closed because of idle timeout. Worse, it could also never return if more requests are queued because the connections would not be idle and therefore not close itself.
###Changes
- Mirgrate shutdown state too
- add tests for this specific case

* simplify testMigrationFromHTTP1ToHTTP2WhileShuttingDown
* add http2 to http1 migration test
2021-12-17 14:44:11 +01:00
Fabian Fett 474b23d677 Typo: Replace HTTPExecutingRequest with HTTPExecutableRequest (#514) 2021-12-03 17:10:55 +01:00
David Nadoba 99bd384b38 Refactor deconstructURL and scheme parsing (#504)
* make `Scheme` a type

* introduce new Endpoint type

* use endpoint as storage in `HTTPClient.Request`

* fix merge conflicts

* rename Endpoint to DeconstructedURL

* swift-format

* make `DeconstructedURL` properties `var`'s

* move scheme into global namespace

- rename `useTLS` to `usesTLS` where posible without breaking public API
- only import Foundation.URL

* fix review comments
2021-12-01 13:03:09 +01:00
David Nadoba 591aa445d9 fix nits from #501 (#503) 2021-11-30 18:47:13 +01:00
Karl f1a91872c5 Introduce a ConnectionTarget enum (#501)
* Add a ConnectionPool.Host enum

* Move Host out as a top-level ConnectionTarget type, and use it in Request.
2021-11-30 18:29:38 +01:00
David Nadoba 9eaecbbbce SwiftFormat --ifdef no-indent (#494)
* SwiftFormat --ifdef no-indent

* update `generate_linux_tests.rb` to use new indention rule
2021-11-25 17:09:19 +01:00
Fabian Fett e5022468bb Update swiftformat to 0.48.8 (#491)
### Motivation

Our current swiftformat version does not support async/await. Since we want to add support for async/await we must update swiftformat or disable it. I tried my very best to keep the number of changes as small as possible. I assume we want to stick with the new 0.48.8 for some time.

### Changes

- Update swiftformat to 0.48.8

### Result

We can land async/await code.
2021-11-25 10:15:36 +01:00
David Nadoba 4fd1150184 Fix bodyLengthMissmatch error handling (#490) 2021-11-24 15:46:51 +01:00
David Nadoba 0ed00b8b36 Always overwrite Transport-Encoding and Content-Length headers (#479) 2021-11-23 10:22:57 +01:00
David Nadoba b479afe4c8 Fix bug in migration from HTTP1 to HTTP2 and back to HTTP1 (#486) 2021-11-22 12:33:57 +01:00
Fabian Fett 2fe3f42fee Crash fix: HTTP2Connections emit events after the pool has closed them. (#481) 2021-11-19 12:33:08 +01:00
David Nadoba 1f3f141038 Remove redundant RequestFramingMetadata.Body.none case (#480) 2021-11-18 17:13:38 +01:00
Fabian Fett 7617c35db3 Handle NIOSSLError.uncleanShutdown correctly (#472)
### Motivation

Fixes #238 and #231.

### Changes

- Extracted the unclean shutdown test from `HTTPClientTests` into their own file `HTTPClientUncleanSSLConnectionShutdownTests`
- Copy and pasted @weissi great explanation from #238 into the test file
- Removed property `ignoreUncleanSSLShutdown` everywhere

### Result

`ignoreUncleanSSLShutdown` on `HTTPClient.Configuration` is deprecated and ignored.

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2021-11-11 11:02:54 +01:00
Fabian Fett 170fd536f9 Support informational response heads (#469) 2021-11-10 13:33:38 +01:00
David Nadoba 7d1ed4cca5 [HTTP2] Forward HTTP2 events to StateMachine (#466) 2021-11-04 10:48:12 +00:00
David Nadoba 18a58bb874 [HTTP2] Improve performance of backoff timer done event (#464) 2021-11-03 14:29:24 +00:00
David Nadoba 60fef53db7 [HTTP2] Internal HTTPVersion configuration (#463) 2021-11-02 18:46:29 +00:00
David Nadoba 149b8d2656 [HTTP2] Integrate HTTP2StateMachine into HTTPConnectionPool.StateMachine (#462) 2021-11-02 11:51:18 +00:00
David Nadoba 4147fd647d [HTTP2] Create new connections during migration if needed (#459) 2021-10-27 18:28:51 +02:00
David Nadoba c1a60d8aa4 [HTTP2] Prepare migration actions (#456) 2021-10-13 17:11:04 +02:00
Cory Benfield 1081b0b054 Don't crash when hitting long backoffs. (#458)
Motivation:

If we backoff sufficiently far we can overflow Int64, which will cause
us to crash.

Modifications:

Clamp the backoff value before we convert to Int64.

Results:

No crashes!
2021-10-13 13:09:54 +01:00
David Nadoba d5bd8d6526 Always clear read idle timeout at the end of a request (#455) 2021-10-08 16:29:28 +02:00
David Nadoba a0b09857d8 [HTTP2StateMachine] test and fix HTTP2 go away (#452) 2021-10-05 13:59:09 +02:00
David Nadoba a57c4b309c [HTTP2ConnectionPool] added HTTP2StateMachine (#447) 2021-10-05 11:19:41 +02:00
David Nadoba 96963810cb [HTTP2Connections] Return if connection was idle before lease (#451) 2021-10-02 14:06:13 +02:00
Fabian Fett d928cc81b3 [HTTPRequestStateMachine] Allow channelReadComplete at any time (#450) 2021-10-01 13:59:51 +02:00
Fabian Fett a6ca288e18 [HTTPConnectionPool] StateMachine has explicit function for HTTP1 connection close (#448) 2021-10-01 12:50:13 +02:00
David Nadoba e4e233a2b1 remove umbrella NIO imports and add soundness check (#446) 2021-09-29 17:42:42 +02:00
David Nadoba 628b942522 prepare calculateBackoff(failedAttempt:) to be used in HTTP2StateMachine (#445) 2021-09-29 16:43:10 +02:00
David Nadoba 88d47f12ca [HTTP2ConnectionPool] added HTTP2Connections struct (#440)
One step closer to support HTTP/2 in the new connection pool. 
`HTTP2Connections` will be used in a new `HTTP2StateMaschine` in a follow up PR.
2021-09-28 12:06:54 +02:00
Fabian Fett 16ad7588b1 [HTTP1Connection] Handle 101 Switching Protocols (#442) 2021-09-28 09:52:26 +02:00
Fabian Fett 2a47a1da75 [HTTPClient.Configuration] Make connection pool size configurable (#437) 2021-09-27 09:35:40 +02:00
Fabian Fett dca46a92f0 [HTTPConnectionPool] Fix request timer scheduling (#438) 2021-09-24 15:38:19 +02:00
Fabian Fett 2565dfe0dc [HTTPConnectionPool] Implementation switch (#427) 2021-09-24 09:28:09 +02:00
Fabian Fett 0bce647a2f [HTTPConnectionPool] Fix timer action races (#434)
- `_idleTimer` and `_backoffTimer` are protected by `stateLock`
- Added a new `struct Actions` that splits up actions from the state machine into actions that need to be executed inside the `stateLock` and outside in `stateLock`
- Add HTTP/1.1 connection pool stress test
2021-09-22 16:47:26 +02:00
Fabian Fett d45fa9a0bd [HTTPConnectionPool] Move Connections down in the file (#433) 2021-09-22 15:35:41 +01:00
Fabian Fett 64fbfdaeda [HTTP1Connection] Option to ignore unclean ssl shutdown errors (#432)
- a new `RequestOptions` struct was created, that can be used to set request specific options. It is required by the `HTTPExecutableRequest`
- Added support for `ignoreUncleanSSLShutdown` in the `HTTPRequestStateMachine` and the `HTTP1ConnectionStateMachine`. In http/2 `ignoreUncleanSSLShutdown` is always off.
2021-09-21 10:04:17 +02:00
Fabian Fett b25943adad Fix HTTP/1.0 support (#431)
Use `HTTPResponseHead.isKeepAlive` instead of relying on our own keep-alive test.
2021-09-20 18:16:13 +02:00
Fabian Fett bef8878ede ChannelRead because of closing connection: Remove preconditions (#430)
### Motivation

NIO may send `channelRead` events without a handlers requesting more data with a `context.read()` invocation. This happens if the remote has closed the connection and NIO wants to inform the handlers as soon as possible.

### Changes

- Don't `precondition` on `channelRead` events anymore.
- Close channel if we received an http end without a `context.read()` invocation
2021-09-20 18:11:04 +02:00
Fabian Fett 7c9662d31c Add logging to the new ConnectionPool (#428) 2021-09-20 16:23:09 +02:00
Fabian Fett 324adb73ae HTTP1Connection: Close on error while in request (#425)
### Motivation

In the `HTTP1ConnectionStateMachine` we set the connection state to `.closed` after having forwarded an error to the inner RequestStateMachine. Since we set the state to close, the `state.modify` function did not create an action that would close the connection.

### Changes

- Modify the ConnectionState based on the RequestStateMachine's action only in the `state.modify` function.
- Add a test to verify the fixed behavior.
- Use ExpressibleByDictionaryLiteral syntax for some HTTPHeaders to increase readability.

### Result

Connections are closed, if an error happens, while we are in a request.
2021-09-14 10:27:32 +02:00
Fabian Fett 0c36de21d6 HTTPConnectionPool timeout requests: preserve connection errors
If a request times out because no connection could be attained, we should fail the request with the last connection creation error. If no connection creation error is present and there is no active connection, we fail the request with a connectTimeout error.
2021-09-13 18:22:29 +02:00
Fabian Fett 5d2bf9250d Ensure HTTPConnectionPool calls shutdown on active connections. (#422)
Trigger the correct method on HTTPConnectionPool.Connection to cancel the request and close the connection.
2021-09-13 14:57:18 +02:00
Fabian Fett fb49c1be5f Add new HTTPConnectionPool Manager (#420)
Co-authored-by: George Barnett <gbarnett@apple.com>
2021-09-10 17:25:41 +02:00
Fabian Fett 7bb58e536c Fix a race between shutdown and backoff timer (#419) 2021-09-09 17:01:07 +02:00