Adding -unregisterHTTPOperationClass to AFHTTPClient

Removing 'Accept: applciation/json' default header from AFHTTPClient

Revising documentation for AFHTTPClient
This commit is contained in:
Mattt Thompson 2011-10-12 10:41:59 -05:00
parent e9855af89d
commit b8ca3496f8
4 changed files with 33 additions and 27 deletions

View file

@ -54,7 +54,6 @@ typedef enum {
By default, `AFHTTPClient` sets the following HTTP headers:
- `Accept: application/json`
- `Accept-Encoding: gzip`
- `Accept-Language: #{[NSLocale preferredLanguages]}, en-us;q=0.8`
- `User-Agent: #{generated user agent}`
@ -86,7 +85,7 @@ typedef enum {
@property (nonatomic, assign) NSStringEncoding stringEncoding;
/**
The `AFHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body. This is `AFFormURLParameterEncoding` by default.
*/
@property (nonatomic, assign) AFHTTPClientParameterEncoding parameterEncoding;
@ -113,7 +112,7 @@ typedef enum {
@param url The base URL for the HTTP client. This argument must not be nil.
@discussion This is the designated initializer for `AFHTTPClient`
@discussion This is the designated initializer.
@return The newly-initialized HTTP client
*/
@ -123,8 +122,28 @@ typedef enum {
/// @name Managing HTTP Operations
///----------------------------------
/**
Attempts to register a class conforming to the `AFHTTPClientOperation` protocol, adding it to a chain to automatically generate request operations from a URL request.
@param The class conforming to the `AFHTTPClientOperation` protocol to register
@return `YES` if the registration is successful, `NO` otherwise. The only failure condition is if `operationClass` does not conform to the `AFHTTPCLientOperation` protocol.
@discussion When `requestWithMethod:path:parameters` is invoked, each registered class is consulted in turn to see if it can handle the specific request. The first class to return `YES` when sent a `canProcessRequest:` message is used to generate an operation using `HTTPRequestOperationWithRequest:success:failure:`. There is no guarantee that all registered classes will be consulted. Classes are consulted in the reverse order of their registration. Attempting to register an already-registered class will move it to the top of the chain.
@see `AFHTTPClientOperation`
*/
- (BOOL)registerHTTPOperationClass:(Class)operationClass;
/**
Unregisteres the specified class conforming to the `AFHTTPClientOperation` protocol.
@param The class conforming to the `AFHTTPClientOperation` protocol to unregister
@discussion After this method is invoked, `operationClass` is no longer consulted when `requestWithMethod:path:parameters` is invoked.
*/
- (void)unregisterHTTPOperationClass:(Class)operationClass;
///----------------------------------
/// @name Managing HTTP Header Values
///----------------------------------
@ -367,16 +386,6 @@ typedef enum {
*/
- (void)appendPartWithFileData:(NSData *)data mimeType:(NSString *)mimeType name:(NSString *)name;
/**
Appends the HTTP header `Content-Disposition: file; filename=#{filename}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary.
@param fileURL The URL for the local file to have its contents appended to the form data. This parameter must not be `nil`.
@param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`.
@param fileName The filename to be associated with the file contents. This parameter must not be `nil`.
@param error If an error occurs, upon return contains an `NSError` object that describes the problem.
*/
- (void)appendPartWithFile:(NSURL *)fileURL mimeType:(NSString *)mimeType fileName:(NSString *)fileName error:(NSError **)error;
/**
Appends encoded data to the form data.

View file

@ -163,9 +163,6 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
self.defaultHeaders = [NSMutableDictionary dictionary];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Accept" value:@"application/json"];
// Accept-Encoding HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
[self setDefaultHeader:@"Accept-Encoding" value:@"gzip"];
@ -208,6 +205,11 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
return YES;
}
- (void)unregisterHTTPOperationClass:(Class)operationClass {
NSString *className = NSStringFromClass(operationClass);
[self.registeredHTTPOperationClassNames removeObject:className];
}
#pragma mark -
- (NSString *)defaultValueForHeader:(NSString *)header {
@ -453,17 +455,6 @@ static inline NSString * AFMultipartFormFinalBoundary() {
[self appendPartWithHeaders:mutableHeaders body:data];
}
- (void)appendPartWithFile:(NSURL *)fileURL mimeType:(NSString *)mimeType fileName:(NSString *)fileName error:(NSError **)error {
NSData *data = [NSData dataWithContentsOfFile:[fileURL absoluteString] options:0 error:error];
if (data) {
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
[mutableHeaders setValue:[NSString stringWithFormat:@"file; filename=\"%@\"", fileName] forKey:@"Content-Disposition"];
[mutableHeaders setValue:mimeType forKey:@"Content-Type"];
[self appendPartWithHeaders:mutableHeaders body:data];
}
}
- (void)appendData:(NSData *)data {
[self.mutableData appendData:data];
}

View file

@ -49,6 +49,9 @@ NSString * const kAFGowallaBaseURLString = @"https://api.gowalla.com/";
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Accept" value:@"application/json"];
// X-Gowalla-API-Key HTTP Header; see http://api.gowalla.com/api/docs
[self setDefaultHeader:@"X-Gowalla-API-Key" value:kAFGowallaClientID];

View file

@ -49,6 +49,9 @@ NSString * const kAFGowallaBaseURLString = @"https://api.gowalla.com/";
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Accept" value:@"application/json"];
// X-Gowalla-API-Key HTTP Header; see http://api.gowalla.com/api/docs
[self setDefaultHeader:@"X-Gowalla-API-Key" value:kAFGowallaClientID];