FWHTTPResponseSerializer


@interface FWHTTPResponseSerializer : NSObject <FWURLResponseSerialization>

FWHTTPResponseSerializer conforms to the FWURLRequestSerialization & FWURLResponseSerialization 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 FWHTTPResponseSerializer in order to ensure consistent default behavior.

  • Undocumented

    Declaration

    Objective-C

    - (instancetype)init;
  • Creates and returns a serializer with default configuration.

    Declaration

    Objective-C

    + (nonnull instancetype)serializer;

Configuring Response Serialization

  • 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.

    See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSIndexSet *acceptableStatusCodes;
  • The acceptable MIME types for responses. When non-nil, responses with a Content-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;
  • Sets a user info to be used for the specified response.

    Declaration

    Objective-C

    - (void)setUserInfo:(nullable NSDictionary *)userInfo
            forResponse:(nullable NSURLResponse *)response;
  • Returns the user info of the specified response.

    Declaration

    Objective-C

    - (nullable NSDictionary *)userInfoForResponse:
        (nullable NSURLResponse *)response;
  • 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 *__autoreleasing _Nullable *_Nullable)error;

    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, otherwise NO.