LCHTTPResponseSerializer
Objective-C
@interface LCHTTPResponseSerializer : NSObject <LCURLResponseSerialization>
Swift
class LCHTTPResponseSerializer : NSObject, LCURLResponseSerialization
LCHTTPResponseSerializer
conforms to the LCURLRequestSerialization
& LCURLResponseSerialization
protocols, offering a concrete base implementation of query string / URL form-encoded parameter serialization and default request headers, as well as response status code and content type validation.
Any request or response serializer dealing with HTTP is encouraged to subclass LCHTTPResponseSerializer
in order to ensure consistent default behavior.
-
Undocumented
Declaration
Objective-C
- (instancetype)init;
Swift
init()
-
Deprecated
The string encoding is never used. LCHTTPResponseSerializer only validates status codes and content types but does not try to decode the received data in any way.
Undocumented
Declaration
Objective-C
@property (nonatomic) NSStringEncoding stringEncoding
Swift
var stringEncoding: UInt { get set }
-
Creates and returns a serializer with default configuration.
Declaration
Objective-C
+ (nonnull instancetype)serializer;
-
The acceptable HTTP status codes for responses. When non-
nil
, responses with status codes not contained by the set will result in an error during validation.Declaration
Objective-C
@property (nonatomic, copy, nullable) NSIndexSet *acceptableStatusCodes;
Swift
var acceptableStatusCodes: IndexSet? { get set }
-
The acceptable MIME types for responses. When non-
nil
, responses with aContent-Type
with MIME types that do not intersect with the set will result in an error during validation.Declaration
Objective-C
@property (nonatomic, copy, nullable) NSSet<NSString *> *acceptableContentTypes;
Swift
var acceptableContentTypes: Set<String>? { get set }
-
Validates the specified response and data.
In its base implementation, this method checks for an acceptable status code and content type. Subclasses may wish to add other domain-specific checks.
Declaration
Objective-C
- (BOOL)validateResponse:(nullable NSHTTPURLResponse *)response data:(nullable NSData *)data error:(NSError *_Nullable *_Nullable)error;
Swift
func validate(_ response: HTTPURLResponse?, data: Data?) throws
Parameters
response
The response to be validated.
data
The data associated with the response.
error
The error that occurred while attempting to validate the response.
Return Value
YES
if the response is valid, otherwiseNO
.