Commit Graph

153 Commits

Author SHA1 Message Date
Artem Redkin 49791972c6 add two additional preconditions 2020-08-21 15:39:02 +01:00
Artem Redkin 8c99c41b8d fail if we get part when state is endOrError 2020-08-21 14:56:37 +01:00
Artem Redkin ffcd1e1a1c Fixes double-release of a connection. (#295)
Motivation:
TaskHandler unconditionally releases it's connection on error,
this can lead to double release. This issue actually indicates
a more general issue where handler continues to handle errors
even after its state is `.endOrError`. We need to fix this by
ignoring all subsequent errors.

Modifications:
1. Check state before calling out delegate and pool
2. Replace all error callouts with call to `errorCaught`

Result:
Fixes #294
2020-08-20 15:35:06 +01:00
Tim Condon 1432843305 Fix typo in Task<Response> (#293) 2020-08-20 12:12:18 +01:00
Artem Redkin c9a9bf061d rename connection pool configuration (#288) 1.2.0 2020-07-31 10:06:53 +01:00
Artem Redkin f69b68ffa8 fail if user tries writing bytes after request is sent (#270) 2020-07-30 11:22:55 +01:00
Artem Redkin 2e6a64abb3 add a separate configuration struct for pool (#284)
* add a separate configuration struct for pool

* review fixes

* review fix
2020-07-17 16:06:11 +01:00
Adam Fowler 96a803e98a Use SwiftLogNoOpLogHandler from swift-log (#282)
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Artem Redkin <artem@redkin.me>
2020-07-17 09:47:23 +01:00
Cory Benfield 8b23060fee Kill build warnings. (#283)
Motivation:

Build warnings fail our builds.

Modifications:

- Update minimum NIOSSL version
- Remove the use of the now-unnecessary `try` statement.

Result:

No warnings!
2020-07-16 17:26:26 +01:00
Adam Fowler 643a0dc249 Added default value for queue in HTTPClient.shutdown() (#279)
Default it to .global()
2020-06-29 13:26:06 +01:00
Max Desiatov 9c1c62b183 Avoid horizontal scrolling in README.md code snippets (#276)
Long lines in code snippets make it hard to read, especially on any screen that's not extra-wide, including laptops, tablets and other mobile devices.
2020-06-26 11:15:50 +01:00
Max Desiatov 63fa13ce70 Fix typo in README.md (#272)
`Reponse` -> `response`

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-06-24 08:20:47 +01:00
Max Desiatov dcf7e5c702 Fix invalid code in HTTPClient.swift doc comment (#271)
`HTTPClient(eventLoopGroupProvider = .createNew)` is not a valid Swift expression.
2020-06-24 08:13:30 +01:00
Artem Redkin 61a80a2d34 assume chunked on a stream with no length (#247)
Motivation:
Streams length parameter is optional to allow cases were stream length is not known in advance, but we do not support this in request validation. This PR aims to address that.

Modifications:
Modifies request validation to default to chunked encoding if body length is zero or to passed in content-length header
Adds a test

Result:
Closes #218
2020-06-23 16:42:16 +01:00
Artem Redkin aac4357b65 notify delegate about connect errors (#245) 2020-06-23 15:00:19 +01:00
Dimitri Bouniol 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
Max Desiatov c4f5155384 Fix doc comment for redirectConfiguration (#266)
`redirectConfiguration` can't default to `false` as it's not a boolean value, and the default value is `RedirectConfiguration()`.

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Co-authored-by: Artem Redkin <artem@redkin.me>
2020-06-22 17:39:58 +01:00
Artem Redkin 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 Redkin aec3fee769 All internal connection flow should be executed when shutting down (#268) 2020-06-22 16:11:28 +01:00
Artem Redkin c097c17e3e fix flaky testContentLengthTooLongFails test (#269) 2020-06-22 15:42:37 +01:00
Dimitri Bouniol 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
Johannes Weiss 8e60b94178 use standard ByteBuffer construction methods (#262) 2020-06-17 15:48:11 +01:00
Dimitri Bouniol 275502f482 Updated swift-nio to 2.18.0. (#261)
Motivation:

Due to using new ByteBuffer initializers from https://github.com/apple/swift-nio/releases/tag/2.18.0 in tests (specifically, `ByteBuffer(string: ...)`), the project will no longer compile if an older version of swift-nio is checked out.

Modifications:

Updated swift-nio from 2.16.0 to 2.18.0.

Result:

SPM should now grab the latest version of swift-nio if this version of async-http-client is used.
2020-06-17 15:06:06 +01:00
Artem Redkin 606ab0eaea check body length (#255) 2020-06-16 09:17:09 +01:00
Artem Redkin f2aef45881 fix test faling with NIOTS (#257) 2020-06-15 15:54:47 +01:00
Adam Fowler 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 Redkin a61b31c954 fix test and a crash when closed (#254) 2020-06-15 12:24:08 +01:00
Artem Redkin 5e3b77bc44 add callin tests (#246) 2020-06-14 22:34:50 +01:00
Artem Redkin 238c653181 add a test to make sure that future is bound to delegate el (#241) 2020-06-13 12:35:04 +01:00
Artem Redkin bb8c4fadda Refactor provider shutdown and pending flows (#240) 2020-06-13 11:20:51 +01:00
Johannes Weiss 8add6b8f0b bad certificate can lead to errSSLHandshakeFail or errSSLBadCert (#236) 2020-06-12 16:53:38 +01:00
Johannes Weiss 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 Bouniol 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 Weiss 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 Weiss cb9fd6100d tests: have defaultClient/HTTPBin for less repetition (#224) 2020-05-20 18:51:33 +01:00
Johannes Weiss a3887b259e tests: instead of pre-populating, make use of testOnly_exact (#223) 2020-05-20 17:53:19 +01:00
Artem Redkin f81d0fec12 draft for streaming el fixes (#215) 2020-05-20 15:09:49 +01:00
Artem Redkin ce82178164 fix validation error propagation (#221) 2020-05-20 11:50:13 +01:00
Johannes Weiss 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 Weiss 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 Redkin 8adfdb9bc5 refactor pool (#192) 2020-05-18 17:47:21 +01:00
Fabian Fett b72756af52 Typo fix: Trasfer-Encoding -> Transfer-Encoding (#211) 2020-05-15 14:30:00 +01:00
Artem Redkin 0fbfdcc9f0 fix malformed cookie parsing (#210) 2020-05-13 18:31:36 +01:00
Artem Redkin 75a04337d9 allow empty value cookies (#208) 2020-05-13 09:41:26 +01:00
Artem Redkin f8b8de198c make cookie parsing case insensitive (#207) 2020-05-13 09:34:50 +01:00
Adam Fowler 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 Smith 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
tomer doron 65a55b6ba5 update ci setup (#193)
motivation: 5.2 adoption, prepare for 5.3

changes:
* use 5.2 docker-compose setup
* add 5.3 docker-compose setup (placeholder)
* update format
2020-04-05 13:50:36 -07:00
Fabian Fett 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 Redkin 2fcf0a9fdd fix location header lookup (#186) 2020-03-31 09:56:44 +01:00