-
Closure type handling
DataStreamRequest.Streamvalues.Declaration
Swift
public typealias Handler<Success, Failure> = (Stream<Success, Failure>) throws -> Void where Failure : Error -
Type encapsulating an
See moreEventas it flows through the stream, as well as aCancellationTokenwhich can be used to stop the stream at any time.Declaration
Swift
public struct Stream<Success, Failure> where Failure : Error -
Type representing an event flowing through the stream. Contains either the
See moreResultof processing streamedDataor the completion of the stream.Declaration
Swift
public enum Event<Success, Failure> where Failure : Error -
Value containing the state of a
See moreDataStreamRequestwhen the stream was completed.Declaration
Swift
public struct Completion -
Type used to cancel an ongoing stream.
See moreDeclaration
Swift
public struct CancellationToken -
URLRequestConvertiblevalue used to createURLRequests for this instance.Declaration
Swift
public let convertible: URLRequestConvertible -
Whether or not the instance will be cancelled if stream parsing encounters an error.
Declaration
Swift
public let automaticallyCancelOnStreamError: Bool -
Validates the
URLRequestandHTTPURLResponsereceived for the instance using the providedValidationclosure.Declaration
Swift
@discardableResult public func validate(_ validation: @escaping Validation) -> SelfParameters
validationValidationclosure used to validate the request and response.Return Value
The
DataStreamRequest. -
Produces an
InputStreamthat receives theDatareceived by the instance.Note
The
InputStreamproduced by this method must haveopen()called before being able to readData. Additionally, this method will automatically callresume()on the instance, regardless of whether or not the creating session hasstartRequestsImmediatelyset totrue.Declaration
Swift
public func asInputStream(bufferSize: Int = 1024) -> InputStream?Parameters
bufferSizeSize, in bytes, of the buffer between the
OutputStreamandInputStream.Return Value
The
InputStreambound to the internalOutboundStream.
-
Adds a stream handler which performs no parsing on incoming
Data.Declaration
Swift
@discardableResult public func responseStream(on queue: DispatchQueue = .main, stream: @escaping Handler<Data, Never>) -> SelfParameters
queueDispatchQueueon which to performStreamHandlerclosure.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest. -
Adds a
StreamHandlerwhich uses the providedDataStreamSerializerto process incomingData.Declaration
Swift
@discardableResult public func responseStream<Serializer: DataStreamSerializer>(using serializer: Serializer, on queue: DispatchQueue = .main, stream: @escaping Handler<Serializer.SerializedObject, AFError>) -> SelfParameters
serializerDataStreamSerializerused to process incomingData. Its work is done on theserializationQueue.queueDispatchQueueon which to performStreamHandlerclosure.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest. -
Adds a
StreamHandlerwhich parses incomingDataas a UTF8String.Declaration
Swift
@discardableResult public func responseStreamString(on queue: DispatchQueue = .main, stream: @escaping Handler<String, Never>) -> SelfParameters
queueDispatchQueueon which to performStreamHandlerclosure.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest. -
Adds a
StreamHandlerwhich parses incomingDatausing the providedDataDecoder.Declaration
Swift
@discardableResult public func responseStreamDecodable<T: Decodable>(of type: T.Type = T.self, on queue: DispatchQueue = .main, using decoder: DataDecoder = JSONDecoder(), preprocessor: DataPreprocessor = PassthroughPreprocessor(), stream: @escaping Handler<T, AFError>) -> SelfParameters
typeDecodabletype to parse incomingDatainto.queueDispatchQueueon which to performStreamHandlerclosure.decoderDataDecoderused to decode the incomingData.preprocessorDataPreprocessorused to process the incomingDatabefore it’s passed to thedecoder.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest.
-
A closure used to validate a request that takes a
URLRequestandHTTPURLResponseand returns whether the request was valid.Declaration
Swift
public typealias Validation = (_ request: URLRequest?, _ response: HTTPURLResponse) -> ValidationResult -
Validates that the response has a status code in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate<S>(statusCode acceptableStatusCodes: S) -> Self where S : Sequence, S.Element == IntParameters
statusCodeSequenceof acceptable response status codes.Return Value
The instance.
-
Validates that the response has a content type in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate<S>(contentType acceptableContentTypes: @autoclosure @escaping () -> S) -> Self where S : Sequence, S.Element == StringParameters
contentTypeThe acceptable content types, which may specify wildcard types and/or subtypes.
Return Value
The request.
-
Validates that the response has a status code in the default acceptable range of 200…299, and that the content type matches any specified in the Accept HTTP header field.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate() -> SelfReturn Value
The instance.
View on GitHub
Install in Dash
DataStreamRequest Class Reference