Skip to content

Commit

Permalink
Fixed bugs on 10.6
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldaemon committed Sep 15, 2009
1 parent d798004 commit 66d66a9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
8 changes: 6 additions & 2 deletions NSString+EncodingSHA1.m
Expand Up @@ -18,12 +18,16 @@ - (NSString *)stringByEncodingSHA1Hex
{
const unsigned char *source = [[self dataByEncodingSHA1] bytes];

char finaldigest[2*CC_SHA1_DIGEST_LENGTH];
char finaldigest[2*CC_SHA1_DIGEST_LENGTH+1];
for (NSInteger count = 0; count < CC_SHA1_DIGEST_LENGTH; count++) {
sprintf(finaldigest + count * 2, "%02x", source[count]);
}
finaldigest[2*CC_SHA1_DIGEST_LENGTH] = '\0';

return [NSString stringWithCString:finaldigest length:2 * CC_SHA1_DIGEST_LENGTH];
return [NSString
stringWithCString:finaldigest
encoding:NSASCIIStringEncoding
];
}

@end
Expand Down
20 changes: 20 additions & 0 deletions SimpleHttpClientOperation.m
Expand Up @@ -104,9 +104,29 @@ - (void)start
return;
}

[NSThread
detachNewThreadSelector:@selector(main)
toTarget:self
withObject:nil
];

[self setValue:[NSNumber numberWithBool:YES] forKey:@"isExecuting"];
}

- (void)main
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

_connection = [NSURLConnection connectionWithRequest:_request delegate:self];

do {
[[NSRunLoop currentRunLoop]
runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]
];
} while (![self isFinished]);

[pool release];
}

- (void)cancel
Expand Down
1 change: 1 addition & 0 deletions test/TestEncodingSHA1.m
Expand Up @@ -10,6 +10,7 @@ @implementation TestEncodingSHA1
- (void)test
{
NSString *sha1hex = [@"debug\ndebug" stringByEncodingSHA1Hex];
NSLog(@"debug");

NSAssert1(
[sha1hex isEqualToString:@"fb91abbf9a90a826933479da50b3b8841c77bc4c"],
Expand Down
23 changes: 15 additions & 8 deletions test/TestSimpleHttpClientRequest.m
Expand Up @@ -9,10 +9,14 @@ @implementation TestSimpleHttpClientRequest

- (void)putsRequest:(SimpleHttpClientRequest *)request
{
NSLog(@"Method : %@\n", request.request.HTTPMethod);
NSLog(@"URL : %@\n", request.request.URL);
NSLog(@"Headers : %@\n", request.request.allHTTPHeaderFields);
NSLog(@"Body : %@\n", request.request.HTTPBody);
NSLog(@"Method : %@", request.request.HTTPMethod);
NSLog(@"URL : %@", request.request.URL);
NSLog(@"Headers : %@", request.request.allHTTPHeaderFields);
if (request.request.HTTPBody) {
NSLog(@"Body : %@", [NSString
stringWithUTF8String:[request.request.HTTPBody bytes]
]);
}
// NSLog(@"Timeout : %@\n", request.request.timeoutInterval);
}

Expand Down Expand Up @@ -85,11 +89,14 @@ - (void)assertHeaderWithRequest:(SimpleHttpClientRequest *)request

- (void)assertBodyWithRequest:(SimpleHttpClientRequest *)request
{
NSData *body = [@"key1=value+value&key2=value%2Bvalue&key3=foo&key3=bar&key3=baz&key4=0%2E1" dataUsingEncoding:NSUTF8StringEncoding];
NSData *body = [@"key3=foo&key3=bar&key3=baz&key1=value+value&key4=0%2E1&key2=value%2Bvalue" dataUsingEncoding:NSUTF8StringEncoding];

NSAssert1(
[body isEqualToData:request.request.HTTPBody],
@"body is %@.", request.request.HTTPBody
@"body is %@.",
[NSString
stringWithUTF8String:[request.request.HTTPBody bytes]
]
);
}

Expand All @@ -106,7 +113,7 @@ - (void)assertGetRequest
[request autorelease];

[self assertMethod:@"GET" request:request];
[self assertUrl:@"http://google.com/?key1=value+value&key2=value%2Bvalue&key3=foo&key3=bar&key3=baz&key4=0%2E1" request:request];
[self assertUrl:@"http://google.com/?key3=foo&key3=bar&key3=baz&key1=value+value&key4=0%2E1&key2=value%2Bvalue" request:request];
[self assertHeaderWithRequest:request];

[self putsRequest:request];
Expand All @@ -125,7 +132,7 @@ - (void)assertDeleteRequest
[request autorelease];

[self assertMethod:@"DELETE" request:request];
[self assertUrl:@"http://google.com/?key1=value+value&key2=value%2Bvalue&key3=foo&key3=bar&key3=baz&key4=0%2E1" request:request];
[self assertUrl:@"http://google.com/?key3=foo&key3=bar&key3=baz&key1=value+value&key4=0%2E1&key2=value%2Bvalue" request:request];
[self assertHeaderWithRequest:request];
[self putsRequest:request];
}
Expand Down

0 comments on commit 66d66a9

Please sign in to comment.