Commit Graph
39 Commits
Author SHA1 Message Date
Johannes WeissandGitHub cb9fd6100d tests: have defaultClient/HTTPBin for less repetition (#224) 2020-05-20 18:51:33 +01:00
Johannes WeissandGitHub a3887b259e tests: instead of pre-populating, make use of testOnly_exact (#223) 2020-05-20 17:53:19 +01:00
Artem RedkinandGitHub f81d0fec12 draft for streaming el fixes (#215) 2020-05-20 15:09:49 +01:00
Artem RedkinandGitHub ce82178164 fix validation error propagation (#221) 2020-05-20 11:50:13 +01:00
Johannes WeissandGitHub 2a344e769f test: that streaming actually works (#219)
Motivation:

We didn't have a test that tested that streaming really streams, ie.
that request body part N arrives before N+1 is sent.

Modification:

Test it.

Result:

Better test coverage.
2020-05-20 11:10:44 +01:00
Johannes WeissandGitHub b1bb7ae243 make public API tests not use @testable again (#216)
Motivation:

AHC's tests were split in HTTPClientTests (which only use the public
API) and HTTPClientInternalTests (which can use `internal` API by using
`@testable`). At some point, the public API tests had `@testable` added
to the AHC import which breaks this idea.

Modification:

Restore the intent by removing `@testable` and moving the 2 tests that
needed it over.

Result:

Cleaner test suite.
2020-05-19 17:44:54 +01:00
Artem RedkinandGitHub 8adfdb9bc5 refactor pool (#192) 2020-05-18 17:47:21 +01:00
5298f20331 Support NIO Transport Services - part 2 (#184)
This is the continuation of the good work of @Yasumoto and @weissi in #135

The following code adds support for NIO Transport services. When the ConnectionPool asks for a connection bootstrap it is returned a NIOClientTCPBootstrap which wraps either a NIOTSConnectionBootstrap or a ClientBootstrap depending on whether the EventLoop we are running on is NIOTSEventLoop.

If you initialize an HTTPClient with eventLoopGroupProvider set to .createNew then if you are running on iOS, macOS 10.14 or later it will provide a NIOTSEventLoopGroup instead of a EventLoopGroup.

Currently a number of tests are failing. 4 of these are related to the NIOSSLUncleanShutdown error the others all seem related to various race conditions which are being dealt with on other PRs. I have tested this code with aws-sdk-swift and it is working on both macOS and iOS.

Things look into:

The aws-sdk-swift NIOTS HTTP client had issues with on Mojave. We should check if this is the case for async-http-client as well.

Co-authored-by: Joe Smith <yasumoto7@gmail.com>
Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-04-18 14:17:46 +01:00
Iain SmithandGitHub be517e3cc1 Enable clients to call URLs that include %2F as an escaped backslash (#201)
* Enable clients to call URLs that include %2F as an escaped backslash

Previously `percentEncodedPath` was using `path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)`
which converts %2F to a literal '/'. This prevented users fetching URLs like https://api.travis-ci.org/repo/github/rails%2Frails
which use %2F as part of a path segment.

Migrating to `URLComponents(url: self, resolvingAgainstBaseURL: false)?.percentEncodedPath` has the desired behaviour
for the couple of test cases that exist.

Updated the test server to switch on the `percentEncodedPath` so it's easier
to understand the desired behaviour.
2020-04-15 11:24:30 +01:00
Fabian FettandGitHub 2d88de3eb6 Verify header field names (#191)
* HTTPRequest without body: Content-Length shall not be send
* Verify field names comply with RFC7230
2020-04-01 16:48:01 +01:00
Artem RedkinandGitHub a6d1ebe302 Implement asynchronous shutdown (#183) 2020-03-30 13:23:34 +01:00
TrevörandGitHub 38bef7c546 Fix leaked TLS handshake promise (#180) (#180)
motivation:
TLS handshake promise was leaked in some cases of failure (see #179)

changes:
- Avoid leaking promise
- Clearer completion flow for related futures
- Add testAvoidLeakingTLSHandshakeCompletionPromise test
2020-03-12 18:37:19 +00:00
9cdd1dc389 Close idle pool connections (#170)
* Close idle pool connections

Motivation: Pooled connections should close at some point (see #168)

Changes:
- Add new poolingTimeout property to HTTPClient.Configuration, it's
default value is .seconds(60), it can be set to nil if one wishes to
disable this timeout.
- Add relevant unit test

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-03-03 21:51:50 +00:00
Johannes WeissandGitHub 2745c08d1a add extra test case (#166)
Motivation:

I wasn't sure if we tested that we would successfully recover from
a server that sometimes closes the connection on us.

Modification:

Added a test case where we do three requests: First one succeeds,
second one gets a close from the server, third one succeeds again.
So we're testing that although AsyncHTTPClient doesn't auto-retry, the
user can just retry again.

Result:

More test coverage.
2020-02-25 17:25:24 +00:00
TrevörandGitHub 19e2ea727e Add an HTTP/1.1 connection pool (#105)
motivation: Better performance thanks to connection reuse

changes:
- Added a connection pool for HTTP/1.1
- All requests automatically use the connection pool
- Up to 8 parallel connections per (scheme, host, port)
- Multiple additional unit tests
2020-02-25 15:43:16 +00:00
Johannes WeissandGitHub de7421906c fix UDS without a baseURL (#165)
Previously, UNIX Domain Sockets would only work if the URL also had a
"base URL". If it didn't have a base URL, it would try to connect to the
empty string which would fail :).

Now, we support both cases:
- URLs with a baseURL (the path to the UDS) and a path (actual path)
- URLs that just have an actual path (path to the UDS) where we'll just
  use "/" as the URL's path
2020-02-24 17:52:36 +00:00
Johannes WeissandGitHub 8031c46933 add a test that does many equal concurrent requests (#160) 2020-02-05 15:57:18 +00:00
Marcin KrzyzanowskiandJohannes Weiss e90f5fd03d Support UNIX Domain Sockets (#151)
Adds support for UNIX Domain Socket requests.

Usage:

```
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
let socketURL = URL(string: "unix:///var/run/docker.sock")!
let req = try HTTPClient.Request(url: URL(string: "/users/list", relativeTo: socketURL)!, method: .GET)
let response = try httpClient.execute(request: req).wait()
```
2020-01-27 15:55:12 +00:00
Andreas KostuchandJohannes Weiss 8f2f7b1691 Bugfix HTTPS SNI and IP Address (#139)
* Bugfix HTTPS SNI and IP Address

Motivation:

Solving the SNI Bug

Modifications:

Added an internal extension on String for checking if the hostname is an IP Address -- see the private extension on SNI. Additionally using the IPv4Address and IPv6Address Function from Network above 10.14 as protecting with #availabe.
Adding the test for HTTPS and IP in as hostname

Result:

We get results with an IP as Hostname
2019-12-16 22:21:25 +00:00
Johannes WeissandGitHub d2d7bde0ca add test where server sends connection: close (#143)
Motivation:

We need a test that we can handle servers that repeatedly send
connection: closes.

Modification:

Add a unit test that always makes the server send connection: close.

Result:

More test coverage.
2019-12-15 12:57:06 +00:00
Johannes WeissandGitHub de4d1add8d add a parallel test case (#140)
Motivation:

It's important to also have a test case where async-http-client is
actually used to do multiple parallel requests on multiple workers.

Modification:

Add a test where 5 workers are doing 100 requests each.

Result:

Better test coverage.
2019-12-06 17:40:45 +00:00
Johannes WeissandGitHub 7aeaf6f0e1 a set of extra test cases (#132)
Motivation:

More unit tests are good and now that SwiftNIO shipd
`NIOHTTP1TestServer`, writing integration tests for async-http-client is also
more straightforward.

Modification:

Demonstrate some tests using NIOHTTP1TestServer.

Result:

More tests.
2019-11-18 16:11:30 +01:00
tomer doronandGitHub 018e139eef update copyrights note (#125)
motivation: the Swift Server Workgroup is not a legal entity and cannot hold copyrights. with this change, code authors continue and retain their copyrights under the apache license and previous copyrights note, but Apple steps up instead of the workgroup which has no legal status

changes:
* update header files to say "Apple Inc. and the AsyncHTTPClient project authors" instead of "Swift Server Workgroup and the AsyncHTTPClient project authors"
* update validation scripts to check for the correct header
* add CONTRIBUTING.md file to explain how to make contributions and include a legal notice about licensing the contribution to Apple and the project
* regenerate CONTRIBUTORS.md to reflect most recent contributions
2019-11-06 11:20:30 -08:00
Artem RedkinandGitHub 51dc885a30 add support for redirect limits (#113) 2019-10-23 19:29:25 +03:00
Artem RedkinandJohannes Weiss 191c4ba506 add response decompression support (#86)
fixes #44
2019-10-22 17:45:12 -07:00
Johannes WeissandGitHub 513be15050 EventLoop preference overhaul (#102) 2019-09-21 21:33:15 +02:00
Johannes WeissandArtem Redkin 2d7ae2bbae minor: improve code style (#103) 2019-09-15 11:04:11 +01:00
vkillandJohannes Weiss 47de4bb5ec Add authorization to proxy (#94) 2019-09-08 14:30:24 +01:00
TrevörandJohannes Weiss 244aea673e Tolerate futures from arbitrary event loops (#96)
This commit fixes #95 by always hopping event loop futures received from
the delegate to the right event loop. This could be a source of bugs if
the library users forgot to hop(to:) futures from their delegates
implementations.
2019-09-06 07:40:49 +01:00
Johannes WeissandGitHub 26afbc14bb make sure HTTPClient is shutdown (#98)
Motivation:

Right now, HTTPClient only asserts that it's shut down if it was started with its own EventLoopGroup.
That however is weird because it's lifecycle model depends on the parameters you pass to `init`.

Modifications:

Always validate the lifecycle (in debug mode).

Result:

API makes more sense.
2019-09-05 15:33:13 +01:00
Artem RedkinandGitHub bbf7966992 nest timeout configuration type inside configuration (#93)
* nest timeout configuration type inside configuration

* move timeout to an extension
2019-08-31 09:49:56 +01:00
Ludovic DewaillyandArtem Redkin 8814439abe redirects ignore EventLoop preference - issue#88 (#89) 2019-08-21 11:26:19 +01:00
Artem RedkinandJohannes Weiss 64851a1a0a add NIO event loop as an argument for execute (#79)
* add NIO event loop as an argument for execute

* review fix: add to np-delegate method as well

* Resolve confict

* add missing linux test

* fix formatting

* missing self

* review fix: add event loop preference argument instead of eventloop

* formatting

* review fix: spelling

* fix compilation error

* review fixes: make preference argument not explicit and add precondition that EL must be part of ELG
2019-08-20 17:50:10 +01:00
vkillandArtem Redkin e0eeb0481c Ignore uncleanShutdown error when state is .head or .body (#77)
* Ignore uncleanShutdown error when state is head or body

* Add ignoreNIOSSLUncleanShutdownError to Configuration

* Revert old HTTPClient.init founctions

* Run generate_linux_tests.rb

* Rename ignoreNIOSSLUncleanShutdownError to ignoreUncleanSSLShutdown

* Make tests compatible with swift 5.0
2019-08-15 11:55:33 +01:00
tomer doronandGitHub e64448e1ef improve request validation (#67)
motivation: safer handling of request validation and mutation

changes:
* drop request version
* made request method and url immutable
* made request scheme and host internal
* fix scheme logic to be non-case sensitive
* adjusted redirect handler implementation to stricter request immutabllity
* adjust and add tests
2019-07-30 09:55:38 -07:00
tomer doronandArtem Redkin bab22d0ebd test formatting issues as part of sanity check (#73)
motivaiton: unified format

changes:
* fix outstanding formatting issues
* add a call to swiftformat as part of sanity script
* fix sanity script language check debugging statements
2019-07-30 10:00:10 +01:00
Artem RedkinandGitHub 9b1e9d3640 add deadlines (#57) 2019-07-03 14:40:26 +03:00
TobiasandJohannes Weiss daf66bde06 Make sure that event loop of task is the same as event loop of channel (#55) 2019-07-03 12:39:42 +01:00
Artem RedkinandGitHub 27fe9265b2 rename to async-http-client (#58) 2019-07-02 14:00:34 +03:00