rejigger things to do callbacks and end-of-stream read properly

This commit is contained in:
Max Lansing 2012-07-19 22:23:38 -07:00
parent d434de241f
commit c7f6fb09bf
2 changed files with 383 additions and 387 deletions

View file

@ -42,10 +42,10 @@ extern NSString * const AFNetworkingReachabilityDidChangeNotification;
*/ */
#ifdef _SYSTEMCONFIGURATION_H #ifdef _SYSTEMCONFIGURATION_H
typedef enum { typedef enum {
AFNetworkReachabilityStatusUnknown = -1, AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0, AFNetworkReachabilityStatusNotReachable = 0,
AFNetworkReachabilityStatusReachableViaWWAN = 1, AFNetworkReachabilityStatusReachableViaWWAN = 1,
AFNetworkReachabilityStatusReachableViaWiFi = 2, AFNetworkReachabilityStatusReachableViaWiFi = 2,
} AFNetworkReachabilityStatus; } AFNetworkReachabilityStatus;
#endif #endif
@ -53,9 +53,9 @@ typedef enum {
Specifies the method used to encode parameters into request body. Specifies the method used to encode parameters into request body.
*/ */
typedef enum { typedef enum {
AFFormURLParameterEncoding, AFFormURLParameterEncoding,
AFJSONParameterEncoding, AFJSONParameterEncoding,
AFPropertyListParameterEncoding, AFPropertyListParameterEncoding,
} AFHTTPClientParameterEncoding; } AFHTTPClientParameterEncoding;
/** /**
@ -116,14 +116,14 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
Both `requestWithMethod:path:parameters` and `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interract: Both `requestWithMethod:path:parameters` and `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interract:
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"]; NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
[NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo [NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz [NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz
[NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo [NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo
[NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo [NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/ [NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/
[NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/ [NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/
*/ */
@interface AFHTTPClient : NSObject @interface AFHTTPClient : NSObject
@ -143,7 +143,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
/** /**
The `AFHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body. This is `AFFormURLParameterEncoding` by default. The `AFHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body. This is `AFFormURLParameterEncoding` by default.
@warning JSON encoding will automatically use JSONKit, SBJSON, YAJL, or NextiveJSON, if provided. Otherwise, the built-in `NSJSONSerialization` class is used, if available (iOS 5.0 and Mac OS 10.7). If the build target does not either support `NSJSONSerialization` or include a third-party JSON library, a runtime exception will be thrown when attempting to encode parameters as JSON. @warning JSON encoding will automatically use JSONKit, SBJSON, YAJL, or NextiveJSON, if provided. Otherwise, the built-in `NSJSONSerialization` class is used, if available (iOS 5.0 and Mac OS 10.7). If the build target does not either support `NSJSONSerialization` or include a third-party JSON library, a runtime exception will be thrown when attempting to encode parameters as JSON.
*/ */
@property (nonatomic, assign) AFHTTPClientParameterEncoding parameterEncoding; @property (nonatomic, assign) AFHTTPClientParameterEncoding parameterEncoding;
@ -155,8 +155,8 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
/** /**
The reachability status from the device to the current `baseURL` of the `AFHTTPClient`. The reachability status from the device to the current `baseURL` of the `AFHTTPClient`.
@warning This property requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (Prefix.pch). @warning This property requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (Prefix.pch).
*/ */
#ifdef _SYSTEMCONFIGURATION_H #ifdef _SYSTEMCONFIGURATION_H
@property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus; @property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
@ -170,7 +170,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
Creates and initializes an `AFHTTPClient` object with the specified base URL. Creates and initializes an `AFHTTPClient` object with the specified base URL.
@param url The base URL for the HTTP client. This argument must not be nil. @param url The base URL for the HTTP client. This argument must not be nil.
@return The newly-initialized HTTP client @return The newly-initialized HTTP client
*/ */
+ (AFHTTPClient *)clientWithBaseURL:(NSURL *)url; + (AFHTTPClient *)clientWithBaseURL:(NSURL *)url;
@ -280,7 +280,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
@param method The HTTP method for the request, such as `GET`, `POST`, `PUT`, or `DELETE`. @param method The HTTP method for the request, such as `GET`, `POST`, `PUT`, or `DELETE`.
@param path The path to be appended to the HTTP client's base URL and used as the request URL. @param path The path to be appended to the HTTP client's base URL and used as the request URL.
@param parameters The parameters to be either set as a query string for `GET` requests, or the request HTTP body. @param parameters The parameters to be either set as a query string for `GET` requests, or the request HTTP body.
@return An `NSMutableURLRequest` object @return An `NSMutableURLRequest` object
*/ */
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
@ -294,7 +294,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
@param path The path to be appended to the HTTP client's base URL and used as the request URL. @param path The path to be appended to the HTTP client's base URL and used as the request URL.
@param parameters The parameters to be encoded and set in the request HTTP body. @param parameters The parameters to be encoded and set in the request HTTP body.
@param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol. This can be used to upload files, encode HTTP body as JSON or XML, or specify multiple values for the same parameter, as one might for array values. @param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol. This can be used to upload files, encode HTTP body as JSON or XML, or specify multiple values for the same parameter, as one might for array values.
@discussion The multipart form data is constructed synchronously in the specified block, so in cases where large amounts of data are being added to the request, you should consider performing this method in the background. Likewise, the form data is constructed in-memory, so it may be advantageous to instead write parts of the form data to a file and stream the request body using the `HTTPBodyStream` property of `NSURLRequest`. @discussion The multipart form data is constructed synchronously in the specified block, so in cases where large amounts of data are being added to the request, you should consider performing this method in the background. Likewise, the form data is constructed in-memory, so it may be advantageous to instead write parts of the form data to a file and stream the request body using the `HTTPBodyStream` property of `NSURLRequest`.
@warning An exception will be raised if the specified method is not `POST`, `PUT` or `DELETE`. @warning An exception will be raised if the specified method is not `POST`, `PUT` or `DELETE`.

File diff suppressed because it is too large Load diff