Merge branch 'fix-cfhttp-cpurl-2141-2138' of https://github.com/ahankinson/cappuccino into ahankinson-fix-cfhttp-cpurl-2141-2138

This commit is contained in:
Antoine Mercadal committed 2014-07-09 15:45:28 -07:00
commit 09f100c0c2
4 files changed
+72 -10

No files matched your search

+37 -7
View File
@@ -79,6 +79,8 @@ var CPURLConnectionDelegate = nil;
BOOL _isCanceled;
BOOL _isLocalFileConnection;
BOOL _withCredentials @accessors(property=withCredentials);
HTTPRequest _HTTPRequest;
}
@@ -95,26 +97,40 @@ var CPURLConnectionDelegate = nil;
@return the data at the URL or \c nil if there was an error
*/
+ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:(/*{*/CPURLResponse/*}*/)aURLResponse
{
var cfHTTPRequest = new CFHTTPRequest();
return [CPURLConnection _sendSynchronousRequest:aRequest returningResponse:aURLResponse withCFHTTPRequest:cfHTTPRequest];
}
+ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:(/*{*/CPURLResponse/*}*/)aURLResponse withCredentials:(BOOL)withCredentials
{
var cfHTTPRequest = new CFHTTPRequest();
cfHTTPRequest.setWithCredentials(withCredentials);
return [CPURLConnection _sendSynchronousRequest:aRequest returningResponse:aURLResponse withCFHTTPRequest:cfHTTPRequest];
}
+ (CPData)_sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:(/*{*/CPURLResponse/*}*/)aURLResponse withCFHTTPRequest:(CFHTTPRequest)aCFHTTPRequest
{
try
{
var request = new CFHTTPRequest();
request.open([aRequest HTTPMethod], [[aRequest URL] absoluteString], NO);
aCFHTTPRequest.open([aRequest HTTPMethod], [[aRequest URL] absoluteString], NO);
var fields = [aRequest allHTTPHeaderFields],
key = nil,
keys = [fields keyEnumerator];
while ((key = [keys nextObject]) !== nil)
request.setRequestHeader(key, [fields objectForKey:key]);
aCFHTTPRequest.setRequestHeader(key, [fields objectForKey:key]);
request.send([aRequest HTTPBody]);
aCFHTTPRequest.send([aRequest HTTPBody]);
if (!request.success())
if (!aCFHTTPRequest.success())
return nil;
return [CPData dataWithRawString:request.responseText()];
return [CPData dataWithRawString:aCFHTTPRequest.responseText()];
}
catch (anException)
{
@@ -134,6 +150,17 @@ var CPURLConnectionDelegate = nil;
return [[self alloc] initWithRequest:aRequest delegate:aDelegate];
}
//overloaded method that allows user to set _withCredentials
+ (CPURLConnection)connectionWithRequest:(CPURLRequest)aRequest delegate:(id)aDelegate withCredentials:(BOOL)withCredentials
{
var connection = [[self alloc] initWithRequest:aRequest delegate:aDelegate startImmediately:NO];
[connection setWithCredentials:withCredentials];
[connection start];
return connection;
}
/*
Default class initializer. Use one of the class methods instead.
@param aRequest contains the URL to contact
@@ -150,6 +177,7 @@ var CPURLConnectionDelegate = nil;
_request = aRequest;
_delegate = aDelegate;
_isCanceled = NO;
_withCredentials = NO;
var URL = [_request URL],
scheme = [URL scheme];
@@ -189,6 +217,8 @@ var CPURLConnectionDelegate = nil;
{
_isCanceled = NO;
_HTTPRequest.setWithCredentials(_withCredentials);
try
{
_HTTPRequest.open([_request HTTPMethod], [[_request URL] absoluteString], YES);
+10
View File
@@ -274,6 +274,16 @@ CFHTTPRequest.prototype.removeEventListener = function(/*String*/ anEventName, /
this._eventDispatcher.removeEventListener(anEventName, anEventListener);
};
CFHTTPRequest.prototype.setWithCredentials = function(/*Boolean*/ willSendWithCredentials)
{
this._nativeRequest.withCredentials = willSendWithCredentials;
};
CFHTTPRequest.prototype.getWithCredentials = function()
{
return this._nativeRequest.withCredentials;
};
function determineAndDispatchHTTPRequestEvents(/*CFHTTPRequest*/ aRequest)
{
var eventDispatcher = aRequest._eventDispatcher;
+9 -3
View File
@@ -20,7 +20,7 @@
- (void)testSynchronousRequestSuccess
{
var req = [CPURLRequest requestWithURL:@"Tests/Foundation/CPURLConnectionTest.j"],
var req = [CPURLRequest requestWithURL:@"Tests/Foundation/CPURLConnectionTest.j"],
data = [CPURLConnection sendSynchronousRequest:req returningResponse:nil];
[self assert:CPData equals:[data class]];
@@ -30,10 +30,16 @@
- (void)testSynchronousRequestNotFound
{
var req = [CPURLRequest requestWithURL:@"NotFound"],
var req = [CPURLRequest requestWithURL:@"NotFound"],
data = [CPURLConnection sendSynchronousRequest:req returningResponse:nil];
[self assertNull:data];
}
@end
- (void)testRequestWithCredentials
{
var connection = [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:@"Tests/Foundation/CPURLConnectionTest.j"] delegate:self withCredentials:YES];
[self assertTrue:[connection withCredentials]];
}
@end
+16
View File
@@ -0,0 +1,16 @@
@import <OJUnit/OJTestCase.j>
@implementation CFHTTPRequestTest : OJTestCase
{
}
- (void)testSetWithCredentials
{
var cfHTTPRequest = new CFHTTPRequest();
[self assertFalse:cfHTTPRequest.getWithCredentials()];
cfHTTPRequest.setWithCredentials(YES);
[self assertTrue:cfHTTPRequest.getWithCredentials()];
}
@end