HTTPClientResponseDelegate
public protocol HTTPClientResponseDelegate : AnyObject
HTTPClientResponseDelegate
allows an implementation to receive notifications about request processing and to control how response parts are processed.
You can implement this protocol if you need fine-grained control over an HTTP request/response, for example, if you want to inspect the response
headers before deciding whether to accept a response body, or if you want to stream your request body. Pass an instance of your conforming
class to the HTTPClient.execute()
method and this package will call each delegate method appropriately as the request takes place.
Note
This delegate is strongly held by theHTTPTaskHandler
for the duration of the Request
processing and will be
released together with the HTTPTaskHandler
when channel is closed.
Users of the library are not required to keep a reference to the
object that implements this protocol, but may do so if needed.
-
Undocumented
Declaration
Swift
associatedtype Response
-
didSendRequestHead(task:
Default implementation_: ) Called when the request head is sent. Will be called once.
Default Implementation
Declaration
Swift
func didSendRequestHead(task: HTTPClient.Task<Response>, _ head: HTTPRequestHead)
Parameters
task
Current request context.
head
Request head.
-
didSendRequestPart(task:
Default implementation_: ) Called when a part of the request body is sent. Could be called zero or more times.
Default Implementation
Declaration
Swift
func didSendRequestPart(task: HTTPClient.Task<Response>, _ part: IOData)
Parameters
task
Current request context.
part
Request body
Part
. -
didSendRequest(task:
Default implementation) Called when the request is fully sent. Will be called once.
Default Implementation
Declaration
Swift
func didSendRequest(task: HTTPClient.Task<Response>)
Parameters
task
Current request context.
-
didReceiveHead(task:
Default implementation_: ) Called when response head is received. Will be called once. You must return an
EventLoopFuture<Void>
that you complete when you have finished processing the body part. You can create an already succeeded future by callingtask.eventLoop.makeSucceededFuture(())
.Default Implementation
Declaration
Swift
func didReceiveHead(task: HTTPClient.Task<Response>, _ head: HTTPResponseHead) -> EventLoopFuture<Void>
Parameters
task
Current request context.
head
Received reposonse head.
Return Value
EventLoopFuture
that will be used for backpressure. -
didReceiveBodyPart(task:
Default implementation_: ) Called when part of a response body is received. Could be called zero or more times. You must return an
EventLoopFuture<Void>
that you complete when you have finished processing the body part. You can create an already succeeded future by callingtask.eventLoop.makeSucceededFuture(())
.Default Implementation
Declaration
Swift
func didReceiveBodyPart(task: HTTPClient.Task<Response>, _ buffer: ByteBuffer) -> EventLoopFuture<Void>
Parameters
task
Current request context.
buffer
Received body
Part
.Return Value
EventLoopFuture
that will be used for backpressure. -
didReceiveError(task:
Default implementation_: ) Called when error was thrown during request execution. Will be called zero or one time only. Request processing will be stopped after that.
Default Implementation
Declaration
Swift
func didReceiveError(task: HTTPClient.Task<Response>, _ error: Error)
Parameters
task
Current request context.
error
Error that occured during response processing.
-
Called when the complete HTTP request is finished. You must return an instance of your
Response
associated type. Will be called once, except if an error occurred.Declaration
Swift
func didFinishRequest(task: HTTPClient.Task<Response>) throws -> Response
Parameters
task
Current request context.
Return Value
Result of processing.