Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

StringResponseSerializer

mattt edited this page Sep 18, 2020 · 2 revisions

StringResponseSerializer

A ResponseSerializer that decodes the response data as a String. By default, a request returning nil or no data is considered an error. However, if the response is has a status code valid for empty responses (204, 205), then an empty String is returned.

public final class StringResponseSerializer:​ ResponseSerializer

Inheritance

ResponseSerializer

Initializers

init(dataPreprocessor:​encoding:​emptyResponseCodes:​emptyRequestMethods:​)

Creates an instance with the provided values.

public init(dataPreprocessor:​ DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor, encoding:​ String.Encoding? = nil, emptyResponseCodes:​ Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods:​ Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods)

Parameters

  • dataPreprocessor:​ DataPreprocessor used to prepare the received Data for serialization.
  • encoding:​ A string encoding. Defaults to nil, in which case the encoding will be determined from the server response, falling back to the default HTTP character set, ISO-8859-1.
  • emptyResponseCodes:​ The HTTP response codes for which empty responses are allowed. [204, 205] by default.
  • emptyRequestMethods:​ The HTTP request methods for which empty responses are allowed. [.head] by default.

Properties

dataPreprocessor

let dataPreprocessor:​ DataPreprocessor

encoding

Optional string encoding used to validate the response.

let encoding:​ String.Encoding?

emptyResponseCodes

let emptyResponseCodes:​ Set<Int>

emptyRequestMethods

let emptyRequestMethods:​ Set<HTTPMethod>

Methods

serialize(request:​response:​data:​error:​)

public func serialize(request:​ URLRequest?, response:​ HTTPURLResponse?, data:​ Data?, error:​ Error?) throws -> String
Types
Protocols
Global Typealiases
Clone this wiki locally