Commit Graph
83 Commits
Author SHA1 Message Date
Artem Redkin 7696be3481 refactor test a bit 2020-06-23 14:35:18 +01:00
Artem Redkin b03074354e Merge branch 'master' into notify_delegate_on_connect_errors 2020-06-23 14:27:31 +01:00
5c7a317f5b Fixed an issue where redirects to socket path-based servers from any server was always allowed (#259)
* Added tests that ensure redirects to unix socket paths from a regular HTTP server are disallowed.

Motivation:

Currently, redirects to any supported URL scheme will always be allowed, despite code being in place to seemingly prevent it. See #230.

Modifications:

- Added a method to HTTPBin to redirect to the specified target.
- Added failing tests that perform redirects from a regular server to a socket-based server and vice versa.

Result:

Failing tests that show that the existing redirect checks were inadequate.

* Fixed an issue where redirects to socket path-based servers from any server was always allowed.

Motivation:

An arbitrary HTTP(S) server should not be able to trigger redirects, and thus activity, to a local socket-path based server, though the opposite may be a valid scenario. Currently, requests in either direction are allowed since the checks don't actually check the destination scheme.

Modifications:

- Refactored `hostSchemes`/`unixSchemes` to `hostRestrictedSchemes`/`allSupportedSchemes`, which better describes what they do.
- Refactored `Request.supports()` to `Request.supportsRedirects(to:)` since it is only used by Redirects now.
- Check the destination URL's scheme rather than the current URL's scheme when validating a redirect.

Result:

Closes #230

Co-authored-by: Artem Redkin <artem@redkin.me>
2020-06-22 17:56:01 +01:00
Artem RedkinandGitHub afe6ae4226 fix missing connect timeout and make tests safer (#267)
* fix missing connect timeout and make tests safer

* swiftformat and linux tests

* fix timeout test

* speedup another test

* make tests safer
2020-06-22 16:19:16 +01:00
Artem RedkinandGitHub aec3fee769 All internal connection flow should be executed when shutting down (#268) 2020-06-22 16:11:28 +01:00
Artem Redkin ef6695e6d7 Merge branch 'master' into notify_delegate_on_connect_errors 2020-06-22 15:51:02 +01:00
Artem RedkinandGitHub c097c17e3e fix flaky testContentLengthTooLongFails test (#269) 2020-06-22 15:42:37 +01:00
Artem Redkin 0970f30537 Merge branch 'master' into notify_delegate_on_connect_errors 2020-06-19 10:53:04 +01:00
Dimitri BouniolandGitHub ec48f4f114 Convenience methods for socket paths (#235)
* Added additional tests for socketPath-based requests

Motivation:

While going through the existing tests, I identified a few more instances where we could add some testing.

Modifications:

Added one test that verifies Requests are being decoded correctly, and improved three others to check for path parsing, error throwing, and schema casing respectively.

Result:

Tests that continue to pass, but that will also catch any incompatible changes in the future.

* Added some convenience initializers to URL and methods to Request for making requests to socket paths

Motivation:

Creating URLs for connecting to servers bound to socket paths currently requires some additional code to get exactly right. It would be nice to have convenience methods on both URL and Request to assist here.

Modifications:

- Refactored the get/post/patch/put/delete methods so they all call into a one line execute() method.
- Added variations on the above methods so they can be called with socket paths (both over HTTP and HTTPS).
- Added public convenience initializers to URL to support the above, and so socket path URLs can be easily created in other situations.
- Added unit tests for creating socket path URLs, and testing the new suite of convenience execute methods (that, er, test `HTTPMETHOD`s). (patch, put, and delete are now also tested as a result of these tests)
- Updated the read me with basic usage instructions.

Result:

New methods that allow for easily creating requests to socket paths, and passing tests to go with them.

* Removed some of the new public methods added for creating a socket-path based request

Motivation:

I previously added too much new public API that will most likely not be necessary, and can be better accessed using a generic execute method.

Modifications:

Removed the get/post/patch/put/delete methods that were specific to socket paths.

Result:

Less new public API.

* Renamed execute(url:) methods such that the HTTP method is the first argument in the parameter list

Motivation:

If these are intended to be general methods for building simple requests, then it makes sense to have the method be the first parameter in the list.

Modifications:

Moved the `method: HTTPMethod` parameter to the front of the list for all `execute([...] url: [...])` methods, and made it default to .GET. I also changed the url parameter to be `urlPath` for the two socketPath based execute methods.

Result:

A cleaner public interface for users of the API.

* Fixed some minor issues introduces with logging

Motivation:

Some of the convenience request methods weren't properly adapted for logging.

Modifications:

- Removed a doc comment from patch() that incorrectly referenced a logger.
- Fixed an issue where patch() would call into post().
- Added a doc comment to delete() that references the logger.
- Tests for the above come in the next commit...

Result:

Correct documentation and functionality for the patch() and delete() methods.

* Updated logging tests to also check the new execute methods

Motivation:

The logging tests previously didn't check for socket path-based requests.

Modifications:

Updated the `testAllMethodsLog()` and `testAllMethodsLog()` tests to include checks for each of the new `execute()` methods.

Result:

Two more tests that pass.
2020-06-19 10:51:03 +01:00
Artem Redkin 747b8a9721 review fix 2020-06-19 10:46:18 +01:00
Artem RedkinandGitHub 8e27e622eb Merge branch 'master' into notify_delegate_on_connect_errors 2020-06-17 15:50:02 +01:00
Johannes WeissandGitHub 8e60b94178 use standard ByteBuffer construction methods (#262) 2020-06-17 15:48:11 +01:00
Artem Redkin 49f742b364 swiftformat and linux tests 2020-06-16 20:01:15 +01:00
Artem Redkin c282a937fe review fix 2020-06-16 19:59:02 +01:00
Artem Redkin 1c123a29ce Merge branch 'master' into notify_delegate_on_connect_errors 2020-06-16 09:51:09 +01:00
Artem RedkinandGitHub 606ab0eaea check body length (#255) 2020-06-16 09:17:09 +01:00
Artem RedkinandGitHub f2aef45881 fix test faling with NIOTS (#257) 2020-06-15 15:54:47 +01:00
Adam FowlerandGitHub 785ced571c The host header should also include the port (#237)
See https://tools.ietf.org/html/rfc7230#section-5.4

If port is not 80 or 443 then add to host header.
Fixed up tests
2020-06-15 15:46:29 +01:00
Artem RedkinandGitHub a61b31c954 fix test and a crash when closed (#254) 2020-06-15 12:24:08 +01:00
Artem Redkin 0b86e7d3a3 Merge branch 'master' into notify_delegate_on_connect_errors 2020-06-15 10:21:50 +01:00
Artem RedkinandGitHub 5e3b77bc44 add callin tests (#246) 2020-06-14 22:34:50 +01:00
Artem Redkin 1687c8900f formatting] 2020-06-13 19:00:31 +01:00
Artem Redkin e2b46a2719 linux tests 2020-06-13 18:59:04 +01:00
Artem Redkin 910a1093e5 notify delegate about connect errors 2020-06-13 18:54:17 +01:00
Artem RedkinandGitHub 238c653181 add a test to make sure that future is bound to delegate el (#241) 2020-06-13 12:35:04 +01:00
Artem RedkinandGitHub bb8c4fadda Refactor provider shutdown and pending flows (#240) 2020-06-13 11:20:51 +01:00
Johannes WeissandGitHub 8add6b8f0b bad certificate can lead to errSSLHandshakeFail or errSSLBadCert (#236) 2020-06-12 16:53:38 +01:00
Johannes WeissandGitHub 86db162a11 logging support (#227)
Motivation:

AsyncHTTPClient is not a simple piece of software and nowadays also
quite stateful. To debug issues, the user may want logging.

Modification:

Support passing a logger to the request methods.

Result:

Debugging simplified.
2020-06-09 15:55:23 +01:00
Dimitri BouniolandGitHub 364d1069a4 Better support for UNIX Domain sockets (#228)
* Added tests for http+unix and https+unix url schemes

Motivation:

Using a base URL as the socket path only works when the URL object is maintained as long as possible through the stack. Additionally, it doesn't currently provide a way to use TLS over UNIX sockets.

Modifications:

Added two tests to test out the to-be supported URL schemes, http+unix, and https+unix, which encode the socket path as a %-escaped hostname, as some existing services already do.

Result:

Better UNIX domain socket support.
2020-06-02 15:22:20 +01:00
Johannes WeissandGitHub 070c1e5f37 cpool: don't reuse connection if we sent close (#225)
Motivation:

Previously, we'd only use the server's connection header to determine if
we should close the connection or not. That's wrong because if we set
`connection: close` ourselves, we must not reuse again.

Modification:

Set `TaskHandler.closing = false` if we send a close header.

Result:

More HTTP correctness.
2020-05-21 15:43:38 +01:00
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
Artem RedkinandGitHub 0fbfdcc9f0 fix malformed cookie parsing (#210) 2020-05-13 18:31:36 +01:00
Artem RedkinandGitHub 75a04337d9 allow empty value cookies (#208) 2020-05-13 09:41:26 +01:00
Artem RedkinandGitHub f8b8de198c make cookie parsing case insensitive (#207) 2020-05-13 09:34:50 +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 2fcf0a9fdd fix location header lookup (#186) 2020-03-31 09:56:44 +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
473c51890f Remove unneeded assertion (#169)
* Remove activity assertion in prepareForClose

motivation: assertion on activity sometimes fails but it turns out it is overly restrictive

changes:
- remove assertion and accept any given activity in prepareForClose

* test closing connections whilst syncShutdown

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-02-27 15:37:33 +00:00
Johannes WeissandGitHub 7768d23528 test that connection close whilst idle works (#167)
Motivation:

I wasn't sure if we actually properly observed an idle connection
suddenly closing. Ideally, if an idle connection just goes away, we just
want to remove it from the connection pool (which is what happens).

Modification:

Add a test that verifies idle connections that get closed from the
server don't get reused in the pool.

Result:

Better test coverage for more complicated scenarios.
2020-02-26 16:11:38 +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