reimplemented multipart form data to use a body streaming object that aggregates file streams and in-memory data objects to compose the request body just in time. also trimmed the multipart form body public API and added CoreMobileServices framework to enable lookup of MIME type by file extension.
This commit is contained in:
parent
5e90a17c76
commit
ced167f867
3 changed files with 811 additions and 571 deletions
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
@class AFHTTPRequestOperation;
|
@class AFHTTPRequestOperation;
|
||||||
@protocol AFHTTPClientOperation;
|
@protocol AFHTTPClientOperation;
|
||||||
@protocol AFMultipartFormData;
|
@protocol AFStreamingMultipartFormData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Posted when network reachability changes.
|
Posted when network reachability changes.
|
||||||
|
|
@ -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,13 +116,13 @@ 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
|
||||||
|
|
@ -156,7 +156,7 @@ 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;
|
||||||
|
|
@ -304,7 +304,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
|
||||||
- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
|
- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
|
||||||
path:(NSString *)path
|
path:(NSString *)path
|
||||||
parameters:(NSDictionary *)parameters
|
parameters:(NSDictionary *)parameters
|
||||||
constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block;
|
constructingBodyWithBlock:(void (^)(id <AFStreamingMultipartFormData> formData))block;
|
||||||
|
|
||||||
///-------------------------------
|
///-------------------------------
|
||||||
/// @name Creating HTTP Operations
|
/// @name Creating HTTP Operations
|
||||||
|
|
@ -457,15 +457,10 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
|
||||||
|
|
||||||
@see `AFHTTPClient -multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:`
|
@see `AFHTTPClient -multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:`
|
||||||
*/
|
*/
|
||||||
@protocol AFMultipartFormData
|
|
||||||
|
|
||||||
/**
|
|
||||||
Appends HTTP headers, followed by the encoded data and the multipart form boundary.
|
|
||||||
|
|
||||||
@param headers The HTTP headers to be appended to the form data.
|
@protocol AFStreamingMultipartFormData
|
||||||
@param body The data to be encoded and appended to the form data.
|
|
||||||
*/
|
|
||||||
- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary.
|
Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary.
|
||||||
|
|
@ -473,18 +468,9 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
|
||||||
@param data The data to be encoded and appended to the form data.
|
@param data The data to be encoded and appended to the form data.
|
||||||
@param name The name to be associated with the specified data. This parameter must not be `nil`.
|
@param name The name to be associated with the specified data. This parameter must not be `nil`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name;
|
- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name;
|
||||||
|
|
||||||
/**
|
|
||||||
Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary.
|
|
||||||
|
|
||||||
@param data The data to be encoded and appended to the form data.
|
|
||||||
@param name The name to be associated with the specified 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 specified data. This parameter must not be `nil`.
|
|
||||||
*/
|
|
||||||
- (void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary.
|
Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary.
|
||||||
|
|
||||||
|
|
@ -496,34 +482,8 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete
|
||||||
|
|
||||||
@discussion The filename and MIME type for this data in the form will be automatically generated, using `NSURLResponse` `-suggestedFilename` and `-MIMEType`, respectively.
|
@discussion The filename and MIME type for this data in the form will be automatically generated, using `NSURLResponse` `-suggestedFilename` and `-MIMEType`, respectively.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error;
|
- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error;
|
||||||
|
|
||||||
/**
|
|
||||||
Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary, using NSInputStream to read input.
|
|
||||||
|
|
||||||
@param fileURL The URL corresponding to the file whose content will be appended to the form.
|
|
||||||
@param name The name to be associated with the specified 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`.
|
|
||||||
|
|
||||||
@discussion The filename is generated from the last component of the streamingURL parameter. The size of the buffer used to copy from streamingURL to the output stream is defined by the constant kAFStreamToStreamBufferSize.
|
|
||||||
*/
|
|
||||||
- (void)appendPartWithStreamingURL:(NSURL *)streamingURL
|
|
||||||
name:(NSString *)name
|
|
||||||
mimeType:(NSString *)mimeType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Appends encoded data to the form data.
|
|
||||||
|
|
||||||
@param data The data to be encoded and appended to the form data.
|
|
||||||
*/
|
|
||||||
- (void)appendData:(NSData *)data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Appends a string to the form data.
|
|
||||||
|
|
||||||
@param string The string to be encoded and appended to the form data.
|
|
||||||
*/
|
|
||||||
- (void)appendString:(NSString *)string;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -7,6 +7,7 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
50ABD6ED159FC2CE001BE42C /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50ABD6EC159FC2CE001BE42C /* MobileCoreServices.framework */; };
|
||||||
F8129C7415910C37009BFE23 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C7215910C37009BFE23 /* AppDelegate.m */; };
|
F8129C7415910C37009BFE23 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C7215910C37009BFE23 /* AppDelegate.m */; };
|
||||||
F8D0701B14310F4A00653FD3 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8E469E213957DF700DB05C8 /* SystemConfiguration.framework */; };
|
F8D0701B14310F4A00653FD3 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8E469E213957DF700DB05C8 /* SystemConfiguration.framework */; };
|
||||||
F8D0701C14310F4F00653FD3 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8E469E013957DF100DB05C8 /* Security.framework */; };
|
F8D0701C14310F4F00653FD3 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8E469E013957DF100DB05C8 /* Security.framework */; };
|
||||||
|
|
@ -39,6 +40,7 @@
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
50ABD6EC159FC2CE001BE42C /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
|
||||||
F8129C3815910830009BFE23 /* Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = SOURCE_ROOT; };
|
F8129C3815910830009BFE23 /* Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = SOURCE_ROOT; };
|
||||||
F8129C7215910C37009BFE23 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = SOURCE_ROOT; };
|
F8129C7215910C37009BFE23 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = SOURCE_ROOT; };
|
||||||
F8129C7315910C37009BFE23 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = SOURCE_ROOT; };
|
F8129C7315910C37009BFE23 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
|
@ -95,6 +97,7 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
50ABD6ED159FC2CE001BE42C /* MobileCoreServices.framework in Frameworks */,
|
||||||
F8E469651395739D00DB05C8 /* UIKit.framework in Frameworks */,
|
F8E469651395739D00DB05C8 /* UIKit.framework in Frameworks */,
|
||||||
F8E469671395739D00DB05C8 /* Foundation.framework in Frameworks */,
|
F8E469671395739D00DB05C8 /* Foundation.framework in Frameworks */,
|
||||||
F8E469691395739D00DB05C8 /* CoreGraphics.framework in Frameworks */,
|
F8E469691395739D00DB05C8 /* CoreGraphics.framework in Frameworks */,
|
||||||
|
|
@ -142,6 +145,7 @@
|
||||||
F8E469551395739C00DB05C8 = {
|
F8E469551395739C00DB05C8 = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
50ABD6EC159FC2CE001BE42C /* MobileCoreServices.framework */,
|
||||||
F8E469B71395759C00DB05C8 /* Networking Extensions */,
|
F8E469B71395759C00DB05C8 /* Networking Extensions */,
|
||||||
F8E4696A1395739D00DB05C8 /* Classes */,
|
F8E4696A1395739D00DB05C8 /* Classes */,
|
||||||
F8E469ED1395812A00DB05C8 /* Images */,
|
F8E469ED1395812A00DB05C8 /* Images */,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue