Skip to content

Commit

Permalink
remove unused degate and make other one public+rename (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemredkin authored Jul 4, 2019
1 parent d058f0f commit a42fe83
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
44 changes: 3 additions & 41 deletions Sources/AsyncHTTPClient/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,7 @@
import NIO
import NIOHTTP1

public class HandlingHTTPResponseDelegate<T>: HTTPClientResponseDelegate {
struct EmptyEndHandlerError: Error {}

public typealias Result = T

var handleHead: ((HTTPResponseHead) -> Void)?
var handleBody: ((ByteBuffer) -> Void)?
var handleError: ((Error) -> Void)?
var handleEnd: (() throws -> T)?

public func didReceiveHead(task: HTTPClient.Task<T>, _ head: HTTPResponseHead) -> EventLoopFuture<Void> {
if let handler = handleHead {
handler(head)
}
return task.eventLoop.makeSucceededFuture(())
}

public func didReceivePart(task: HTTPClient.Task<T>, _ buffer: ByteBuffer) -> EventLoopFuture<Void> {
if let handler = handleBody {
handler(buffer)
}
return task.eventLoop.makeSucceededFuture(())
}

public func didReceiveError(task: HTTPClient.Task<T>, _ error: Error) {
if let handler = handleError {
handler(error)
}
}

public func didFinishRequest(task: HTTPClient.Task<T>) throws -> T {
if let handler = handleEnd {
return try handler()
}
throw EmptyEndHandlerError()
}
}

final class CopyingDelegate: HTTPClientResponseDelegate {
public final class HTTPClientCopyingDelegate: HTTPClientResponseDelegate {
public typealias Response = Void

let chunkHandler: (ByteBuffer) -> EventLoopFuture<Void>
Expand All @@ -62,11 +24,11 @@ final class CopyingDelegate: HTTPClientResponseDelegate {
self.chunkHandler = chunkHandler
}

func didReceivePart(task: HTTPClient.Task<Void>, _ buffer: ByteBuffer) -> EventLoopFuture<Void> {
public func didReceivePart(task: HTTPClient.Task<Void>, _ buffer: ByteBuffer) -> EventLoopFuture<Void> {
return self.chunkHandler(buffer)
}

func didFinishRequest(task: HTTPClient.Task<Void>) throws {
public func didFinishRequest(task: HTTPClient.Task<Void>) throws {
return ()
}
}
4 changes: 2 additions & 2 deletions Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class HTTPClientInternalTests: XCTestCase {
var request = try Request(url: "http://localhost:\(httpBin.port)/events/10/1")
request.headers.add(name: "Accept", value: "text/event-stream")

let delegate = CopyingDelegate { part in
let delegate = HTTPClientCopyingDelegate { part in
writer.write(.byteBuffer(part))
}
return httpClient.execute(request: request, delegate: delegate).futureResult
Expand Down Expand Up @@ -122,7 +122,7 @@ class HTTPClientInternalTests: XCTestCase {
var request = try Request(url: "http://localhost:\(httpBin.port)/events/10/1")
request.headers.add(name: "Accept", value: "text/event-stream")

let delegate = CopyingDelegate { _ in
let delegate = HTTPClientCopyingDelegate { _ in
httpClient.eventLoopGroup.next().makeFailedFuture(HTTPClientError.invalidProxyResponse)
}
return httpClient.execute(request: request, delegate: delegate).futureResult
Expand Down

0 comments on commit a42fe83

Please sign in to comment.