Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
[Dox] Document and clean up the PUT logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Feb 18, 2010
1 parent 739cd38 commit c05a31d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/TTURLRequest.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ - (NSString *)md5HexDigest:(NSString*)input {


////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
- (NSString*)generateCacheKey { - (NSString*)generateCacheKey {
if ([_httpMethod isEqualToString:@"POST"] || [_httpMethod isEqualToString:@"PUT"]) { if ([_httpMethod isEqualToString:@"POST"]
|| [_httpMethod isEqualToString:@"PUT"]) {
NSMutableString* joined = [[[NSMutableString alloc] initWithString:self.URL] autorelease]; NSMutableString* joined = [[[NSMutableString alloc] initWithString:self.URL] autorelease];
NSEnumerator* e = [_parameters keyEnumerator]; NSEnumerator* e = [_parameters keyEnumerator];
for (id key; key = [e nextObject]; ) { for (id key; key = [e nextObject]; ) {
Expand Down Expand Up @@ -249,7 +250,8 @@ - (NSMutableDictionary*)parameters {
- (NSData*)httpBody { - (NSData*)httpBody {
if (_httpBody) { if (_httpBody) {
return _httpBody; return _httpBody;
} else if ([[_httpMethod uppercaseString] isEqualToString:@"POST"] || [[_httpMethod uppercaseString] isEqualToString:@"PUT"]) { } else if ([[_httpMethod uppercaseString] isEqualToString:@"POST"]
|| [[_httpMethod uppercaseString] isEqualToString:@"PUT"]) {
return [self generatePostBody]; return [self generatePostBody];
} else { } else {
return nil; return nil;
Expand All @@ -261,7 +263,8 @@ - (NSData*)httpBody {
- (NSString*)contentType { - (NSString*)contentType {
if (_contentType) { if (_contentType) {
return _contentType; return _contentType;
} else if ([_httpMethod isEqualToString:@"POST"] || [_httpMethod isEqualToString:@"PUT"]) { } else if ([_httpMethod isEqualToString:@"POST"]
|| [_httpMethod isEqualToString:@"PUT"]) {
return [NSString stringWithFormat:@"multipart/form-data; boundary=%@", kStringBoundary]; return [NSString stringWithFormat:@"multipart/form-data; boundary=%@", kStringBoundary];
} else { } else {
return nil; return nil;
Expand Down
7 changes: 5 additions & 2 deletions src/TTURLRequestQueue.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -346,8 +346,11 @@ - (BOOL)sendRequest:(TTURLRequest*)request {
request.isLoading = YES; request.isLoading = YES;


TTRequestLoader* loader = nil; TTRequestLoader* loader = nil;
if (![request.httpMethod isEqualToString:@"POST"] && ![request.httpMethod isEqualToString:@"PUT"]) {
// Next, see if there is an active loader for the URL and if so join that bandwagon // If we're not POSTing or PUTting data, let's see if we can jump on an existing request.
if (![request.httpMethod isEqualToString:@"POST"]
&& ![request.httpMethod isEqualToString:@"PUT"]) {
// Next, see if there is an active loader for the URL and if so join that bandwagon.
loader = [_loaders objectForKey:request.cacheKey]; loader = [_loaders objectForKey:request.cacheKey];
if (loader) { if (loader) {
[loader addRequest:request]; [loader addRequest:request];
Expand Down
12 changes: 7 additions & 5 deletions src/Three20/TTURLRequest.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
* *
* @example @"POST" * @example @"POST"
* @example @"GET" * @example @"GET"
* @example @"PUT"
* @default nil (equivalent to @"GET") * @default nil (equivalent to @"GET")
*/ */
@property(nonatomic,copy) NSString* httpMethod; @property(nonatomic,copy) NSString* httpMethod;
Expand All @@ -84,20 +85,21 @@
/** /**
* The HTTP body to send with the request. * The HTTP body to send with the request.
* *
* If provided, will always be used. Please consider this when using POST methods: if httpBody is * If provided, will always be used. Please consider this when using POST/PUT methods: if
* provided, then the POST data generated from the parameters property will not be used. * httpBody is provided, then the POST/PUT data generated from the parameters property will not
* be used.
*/ */
@property(nonatomic,retain) NSData* httpBody; @property(nonatomic,retain) NSData* httpBody;


/** /**
* The content type of the data in the request. * The content type of the data in the request.
* *
* If not provided and httpMethod is POST, then contentType is multipart/form-data. * If not provided and httpMethod is POST/PUT, then contentType is multipart/form-data.
*/ */
@property(nonatomic,copy) NSString* contentType; @property(nonatomic,copy) NSString* contentType;


/** /**
* Parameters to use for an HTTP post. * Parameters to use for an HTTP POST/PUT.
*/ */
@property(nonatomic,readonly) NSMutableDictionary* parameters; @property(nonatomic,readonly) NSMutableDictionary* parameters;


Expand All @@ -120,7 +122,7 @@


/** /**
* If no cache key is provided, a unique key is generated from the request data. If the request * If no cache key is provided, a unique key is generated from the request data. If the request
* is a POST request, then the POST parameters are also used to generate the cache key. * is a POST/PUT request, then the POST/PUT parameters are also used to generate the cache key.
* *
* By setting the cacheKey, you may override the default cache key generator with your own. * By setting the cacheKey, you may override the default cache key generator with your own.
*/ */
Expand Down

0 comments on commit c05a31d

Please sign in to comment.