Skip to content

Commit 7205d36

Browse files
committed
sound?
1 parent 115ce64 commit 7205d36

11 files changed

+156
-103
lines changed

Diff for: Sources/AsyncHTTPClient/ConnectionPool.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ final class ConnectionPool {
7373
taskEventLoop: EventLoop,
7474
deadline: NIODeadline?,
7575
setupComplete: EventLoopFuture<Void>,
76-
logger: Logger) -> EventLoopFuture<Connection> {
76+
logger: Logger) -> EventLoopFuture<Connection>
77+
{
7778
let key = Key(request)
7879

7980
let provider: HTTP1ConnectionProvider = self.lock.withLock {
@@ -210,7 +211,8 @@ class HTTP1ConnectionProvider {
210211
eventLoop: EventLoop,
211212
configuration: HTTPClient.Configuration,
212213
pool: ConnectionPool,
213-
backgroundActivityLogger: Logger) {
214+
backgroundActivityLogger: Logger)
215+
{
214216
self.eventLoop = eventLoop
215217
self.configuration = configuration
216218
self.key = key
@@ -298,7 +300,8 @@ class HTTP1ConnectionProvider {
298300

299301
func getConnection(preference: HTTPClient.EventLoopPreference,
300302
setupComplete: EventLoopFuture<Void>,
301-
logger: Logger) -> EventLoopFuture<Connection> {
303+
logger: Logger) -> EventLoopFuture<Connection>
304+
{
302305
let waiter = Waiter<Connection>(promise: self.eventLoop.makePromise(), setupComplete: setupComplete, preference: preference)
303306

304307
let action: Action = self.lock.withLock {

Diff for: Sources/AsyncHTTPClient/FileDownloadDelegate.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
6666
self.reportHead?(head)
6767

6868
if let totalBytesString = head.headers.first(name: "Content-Length"),
69-
let totalBytes = Int(totalBytesString) {
69+
let totalBytes = Int(totalBytesString)
70+
{
7071
self.progress.totalBytes = totalBytes
7172
}
7273

Diff for: Sources/AsyncHTTPClient/HTTPClient+HTTPCookie.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import Foundation
1616
import NIOHTTP1
1717

18-
extension HTTPClient {
18+
public extension HTTPClient {
1919
/// A representation of an HTTP cookie.
20-
public struct Cookie {
20+
struct Cookie {
2121
/// The name of the cookie.
2222
public var name: String
2323
/// The cookie's string value.
@@ -153,9 +153,9 @@ extension HTTPClient {
153153
}
154154
}
155155

156-
extension HTTPClient.Response {
156+
public extension HTTPClient.Response {
157157
/// List of HTTP cookies returned by the server.
158-
public var cookies: [HTTPClient.Cookie] {
158+
var cookies: [HTTPClient.Cookie] {
159159
return self.headers["set-cookie"].compactMap { HTTPClient.Cookie(header: $0, defaultDomain: self.host) }
160160
}
161161
}

Diff for: Sources/AsyncHTTPClient/HTTPClient.swift

+28-16
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public class HTTPClient {
7878
/// - eventLoopGroupProvider: Specify how `EventLoopGroup` will be created.
7979
/// - configuration: Client configuration.
8080
public convenience init(eventLoopGroupProvider: EventLoopGroupProvider,
81-
configuration: Configuration = Configuration()) {
81+
configuration: Configuration = Configuration())
82+
{
8283
self.init(eventLoopGroupProvider: eventLoopGroupProvider,
8384
configuration: configuration,
8485
backgroundActivityLogger: HTTPClient.loggingDisabled)
@@ -91,7 +92,8 @@ public class HTTPClient {
9192
/// - configuration: Client configuration.
9293
public required init(eventLoopGroupProvider: EventLoopGroupProvider,
9394
configuration: Configuration = Configuration(),
94-
backgroundActivityLogger: Logger) {
95+
backgroundActivityLogger: Logger)
96+
{
9597
self.eventLoopGroupProvider = eventLoopGroupProvider
9698
switch self.eventLoopGroupProvider {
9799
case .shared(let group):
@@ -424,7 +426,8 @@ public class HTTPClient {
424426
public func execute(request: Request,
425427
eventLoop eventLoopPreference: EventLoopPreference,
426428
deadline: NIODeadline? = nil,
427-
logger: Logger?) -> EventLoopFuture<Response> {
429+
logger: Logger?) -> EventLoopFuture<Response>
430+
{
428431
let accumulator = ResponseAccumulator(request: request)
429432
return self.execute(request: request, delegate: accumulator, eventLoop: eventLoopPreference, deadline: deadline, logger: logger).futureResult
430433
}
@@ -437,7 +440,8 @@ public class HTTPClient {
437440
/// - deadline: Point in time by which the request must complete.
438441
public func execute<Delegate: HTTPClientResponseDelegate>(request: Request,
439442
delegate: Delegate,
440-
deadline: NIODeadline? = nil) -> Task<Delegate.Response> {
443+
deadline: NIODeadline? = nil) -> Task<Delegate.Response>
444+
{
441445
return self.execute(request: request, delegate: delegate, deadline: deadline, logger: HTTPClient.loggingDisabled)
442446
}
443447

@@ -451,7 +455,8 @@ public class HTTPClient {
451455
public func execute<Delegate: HTTPClientResponseDelegate>(request: Request,
452456
delegate: Delegate,
453457
deadline: NIODeadline? = nil,
454-
logger: Logger) -> Task<Delegate.Response> {
458+
logger: Logger) -> Task<Delegate.Response>
459+
{
455460
return self.execute(request: request, delegate: delegate, eventLoop: .indifferent, deadline: deadline, logger: logger)
456461
}
457462

@@ -466,7 +471,8 @@ public class HTTPClient {
466471
public func execute<Delegate: HTTPClientResponseDelegate>(request: Request,
467472
delegate: Delegate,
468473
eventLoop eventLoopPreference: EventLoopPreference,
469-
deadline: NIODeadline? = nil) -> Task<Delegate.Response> {
474+
deadline: NIODeadline? = nil) -> Task<Delegate.Response>
475+
{
470476
return self.execute(request: request,
471477
delegate: delegate,
472478
eventLoop: eventLoopPreference,
@@ -485,7 +491,8 @@ public class HTTPClient {
485491
delegate: Delegate,
486492
eventLoop eventLoopPreference: EventLoopPreference,
487493
deadline: NIODeadline? = nil,
488-
logger originalLogger: Logger?) -> Task<Delegate.Response> {
494+
logger originalLogger: Logger?) -> Task<Delegate.Response>
495+
{
489496
let logger = (originalLogger ?? HTTPClient.loggingDisabled).attachingRequestInformation(request, requestID: globalRequestID.add(1))
490497
let taskEL: EventLoop
491498
switch eventLoopPreference.preference {
@@ -666,7 +673,8 @@ public class HTTPClient {
666673
connectionPool: ConnectionPool = ConnectionPool(),
667674
proxy: Proxy? = nil,
668675
ignoreUncleanSSLShutdown: Bool = false,
669-
decompression: Decompression = .disabled) {
676+
decompression: Decompression = .disabled)
677+
{
670678
self.tlsConfiguration = tlsConfiguration
671679
self.redirectConfiguration = redirectConfiguration ?? RedirectConfiguration()
672680
self.timeout = timeout
@@ -681,7 +689,8 @@ public class HTTPClient {
681689
timeout: Timeout = Timeout(),
682690
proxy: Proxy? = nil,
683691
ignoreUncleanSSLShutdown: Bool = false,
684-
decompression: Decompression = .disabled) {
692+
decompression: Decompression = .disabled)
693+
{
685694
self.init(
686695
tlsConfiguration: tlsConfiguration,
687696
redirectConfiguration: redirectConfiguration,
@@ -699,7 +708,8 @@ public class HTTPClient {
699708
maximumAllowedIdleTimeInConnectionPool: TimeAmount = .seconds(60),
700709
proxy: Proxy? = nil,
701710
ignoreUncleanSSLShutdown: Bool = false,
702-
decompression: Decompression = .disabled) {
711+
decompression: Decompression = .disabled)
712+
{
703713
self.init(tlsConfiguration: TLSConfiguration.forClient(certificateVerification: certificateVerification),
704714
redirectConfiguration: redirectConfiguration,
705715
timeout: timeout,
@@ -716,7 +726,8 @@ public class HTTPClient {
716726
proxy: Proxy? = nil,
717727
ignoreUncleanSSLShutdown: Bool = false,
718728
decompression: Decompression = .disabled,
719-
backgroundActivityLogger: Logger?) {
729+
backgroundActivityLogger: Logger?)
730+
{
720731
self.init(tlsConfiguration: TLSConfiguration.forClient(certificateVerification: certificateVerification),
721732
redirectConfiguration: redirectConfiguration,
722733
timeout: timeout,
@@ -731,7 +742,8 @@ public class HTTPClient {
731742
timeout: Timeout = Timeout(),
732743
proxy: Proxy? = nil,
733744
ignoreUncleanSSLShutdown: Bool = false,
734-
decompression: Decompression = .disabled) {
745+
decompression: Decompression = .disabled)
746+
{
735747
self.init(
736748
certificateVerification: certificateVerification,
737749
redirectConfiguration: redirectConfiguration,
@@ -820,9 +832,9 @@ public class HTTPClient {
820832
}
821833
}
822834

823-
extension HTTPClient.Configuration {
835+
public extension HTTPClient.Configuration {
824836
/// Timeout configuration.
825-
public struct Timeout {
837+
struct Timeout {
826838
/// Specifies connect timeout.
827839
public var connect: TimeAmount?
828840
/// Specifies read timeout.
@@ -840,7 +852,7 @@ extension HTTPClient.Configuration {
840852
}
841853

842854
/// Specifies redirect processing settings.
843-
public struct RedirectConfiguration {
855+
struct RedirectConfiguration {
844856
enum Configuration {
845857
/// Redirects are not followed.
846858
case disallow
@@ -872,7 +884,7 @@ extension HTTPClient.Configuration {
872884
}
873885

874886
/// Connection pool configuration.
875-
public struct ConnectionPool: Hashable {
887+
struct ConnectionPool: Hashable {
876888
// Specifies amount of time connections are kept idle in the pool.
877889
public var idleTimeout: TimeAmount
878890

Diff for: Sources/AsyncHTTPClient/HTTPHandler.swift

+32-23
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import NIOHTTP1
2121
import NIOHTTPCompression
2222
import NIOSSL
2323

24-
extension HTTPClient {
24+
public extension HTTPClient {
2525
/// Represent request body.
26-
public struct Body {
26+
struct Body {
2727
/// Chunk provider.
2828
public struct StreamWriter {
2929
let closure: (IOData) -> EventLoopFuture<Void>
@@ -93,7 +93,7 @@ extension HTTPClient {
9393
}
9494

9595
/// Represent HTTP request.
96-
public struct Request {
96+
struct Request {
9797
/// Represent kind of Request
9898
enum Kind: Equatable {
9999
enum UnixScheme: Equatable {
@@ -258,7 +258,7 @@ extension HTTPClient {
258258
}
259259

260260
/// Represent HTTP response.
261-
public struct Response {
261+
struct Response {
262262
/// Remote host of the request.
263263
public var host: String
264264
/// Response HTTP status.
@@ -304,7 +304,7 @@ extension HTTPClient {
304304
}
305305

306306
/// HTTP authentication
307-
public struct Authorization {
307+
struct Authorization {
308308
private enum Scheme {
309309
case Basic(String)
310310
case Bearer(String)
@@ -484,22 +484,22 @@ public protocol HTTPClientResponseDelegate: AnyObject {
484484
func didFinishRequest(task: HTTPClient.Task<Response>) throws -> Response
485485
}
486486

487-
extension HTTPClientResponseDelegate {
488-
public func didSendRequestHead(task: HTTPClient.Task<Response>, _ head: HTTPRequestHead) {}
487+
public extension HTTPClientResponseDelegate {
488+
func didSendRequestHead(task: HTTPClient.Task<Response>, _ head: HTTPRequestHead) {}
489489

490-
public func didSendRequestPart(task: HTTPClient.Task<Response>, _ part: IOData) {}
490+
func didSendRequestPart(task: HTTPClient.Task<Response>, _ part: IOData) {}
491491

492-
public func didSendRequest(task: HTTPClient.Task<Response>) {}
492+
func didSendRequest(task: HTTPClient.Task<Response>) {}
493493

494-
public func didReceiveHead(task: HTTPClient.Task<Response>, _: HTTPResponseHead) -> EventLoopFuture<Void> {
494+
func didReceiveHead(task: HTTPClient.Task<Response>, _: HTTPResponseHead) -> EventLoopFuture<Void> {
495495
return task.eventLoop.makeSucceededFuture(())
496496
}
497497

498-
public func didReceiveBodyPart(task: HTTPClient.Task<Response>, _: ByteBuffer) -> EventLoopFuture<Void> {
498+
func didReceiveBodyPart(task: HTTPClient.Task<Response>, _: ByteBuffer) -> EventLoopFuture<Void> {
499499
return task.eventLoop.makeSucceededFuture(())
500500
}
501501

502-
public func didReceiveError(task: HTTPClient.Task<Response>, _: Error) {}
502+
func didReceiveError(task: HTTPClient.Task<Response>, _: Error) {}
503503
}
504504

505505
extension URL {
@@ -555,10 +555,10 @@ extension URL {
555555
}
556556
}
557557

558-
extension HTTPClient {
558+
public extension HTTPClient {
559559
/// Response execution context. Will be created by the library and could be used for obtaining
560560
/// `EventLoopFuture<Response>` of the execution or cancellation of the execution.
561-
public final class Task<Response> {
561+
final class Task<Response> {
562562
/// The `EventLoop` the delegate will be executed on.
563563
public let eventLoop: EventLoop
564564

@@ -624,15 +624,17 @@ extension HTTPClient {
624624
func succeed<Delegate: HTTPClientResponseDelegate>(promise: EventLoopPromise<Response>?,
625625
with value: Response,
626626
delegateType: Delegate.Type,
627-
closing: Bool) {
627+
closing: Bool)
628+
{
628629
self.releaseAssociatedConnection(delegateType: delegateType,
629630
closing: closing).whenSuccess {
630631
promise?.succeed(value)
631632
}
632633
}
633634

634635
func fail<Delegate: HTTPClientResponseDelegate>(with error: Error,
635-
delegateType: Delegate.Type) {
636+
delegateType: Delegate.Type)
637+
{
636638
if let connection = self.connection {
637639
self.releaseAssociatedConnection(delegateType: delegateType, closing: true)
638640
.whenSuccess {
@@ -646,7 +648,8 @@ extension HTTPClient {
646648
}
647649

648650
func releaseAssociatedConnection<Delegate: HTTPClientResponseDelegate>(delegateType: Delegate.Type,
649-
closing: Bool) -> EventLoopFuture<Void> {
651+
closing: Bool) -> EventLoopFuture<Void>
652+
{
650653
if let connection = self.connection {
651654
// remove read timeout handler
652655
return connection.removeHandler(IdleStateHandler.self).flatMap {
@@ -706,7 +709,8 @@ internal class TaskHandler<Delegate: HTTPClientResponseDelegate>: RemovableChann
706709
delegate: Delegate,
707710
redirectHandler: RedirectHandler<Delegate.Response>?,
708711
ignoreUncleanSSLShutdown: Bool,
709-
logger: Logger) {
712+
logger: Logger)
713+
{
710714
self.task = task
711715
self.delegate = delegate
712716
self.redirectHandler = redirectHandler
@@ -720,7 +724,8 @@ internal class TaskHandler<Delegate: HTTPClientResponseDelegate>: RemovableChann
720724

721725
extension TaskHandler {
722726
func failTaskAndNotifyDelegate<Err: Error>(error: Err,
723-
_ body: @escaping (HTTPClient.Task<Delegate.Response>, Err) -> Void) {
727+
_ body: @escaping (HTTPClient.Task<Delegate.Response>, Err) -> Void)
728+
{
724729
func doIt() {
725730
body(self.task, error)
726731
self.task.fail(with: error, delegateType: Delegate.self)
@@ -740,7 +745,8 @@ extension TaskHandler {
740745
}
741746

742747
func callOutToDelegateFireAndForget<Value>(value: Value,
743-
_ body: @escaping (HTTPClient.Task<Delegate.Response>, Value) -> Void) {
748+
_ body: @escaping (HTTPClient.Task<Delegate.Response>, Value) -> Void)
749+
{
744750
if self.task.eventLoop.inEventLoop {
745751
body(self.task, value)
746752
} else {
@@ -752,7 +758,8 @@ extension TaskHandler {
752758

753759
func callOutToDelegate<Value>(value: Value,
754760
channelEventLoop: EventLoop,
755-
_ body: @escaping (HTTPClient.Task<Delegate.Response>, Value) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
761+
_ body: @escaping (HTTPClient.Task<Delegate.Response>, Value) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>
762+
{
756763
if self.task.eventLoop.inEventLoop {
757764
return body(self.task, value).hop(to: channelEventLoop)
758765
} else {
@@ -763,7 +770,8 @@ extension TaskHandler {
763770
}
764771

765772
func callOutToDelegate<Response>(promise: EventLoopPromise<Response>? = nil,
766-
_ body: @escaping (HTTPClient.Task<Delegate.Response>) throws -> Response) where Response == Delegate.Response {
773+
_ body: @escaping (HTTPClient.Task<Delegate.Response>) throws -> Response) where Response == Delegate.Response
774+
{
767775
func doIt() {
768776
do {
769777
let result = try body(self.task)
@@ -787,7 +795,8 @@ extension TaskHandler {
787795
}
788796

789797
func callOutToDelegate<Response>(channelEventLoop: EventLoop,
790-
_ body: @escaping (HTTPClient.Task<Delegate.Response>) throws -> Response) -> EventLoopFuture<Response> where Response == Delegate.Response {
798+
_ body: @escaping (HTTPClient.Task<Delegate.Response>) throws -> Response) -> EventLoopFuture<Response> where Response == Delegate.Response
799+
{
791800
let promise = channelEventLoop.makePromise(of: Response.self)
792801
self.callOutToDelegate(promise: promise, body)
793802
return promise.futureResult

0 commit comments

Comments
 (0)