diff --git a/Foundation/CPJSONPConnection.j b/Foundation/CPJSONPConnection.j index f721291f7..8ec76e0e7 100644 --- a/Foundation/CPJSONPConnection.j +++ b/Foundation/CPJSONPConnection.j @@ -73,7 +73,7 @@ CPJSONPCallbackReplacementString = @"${JSONP_CALLBACK}"; _callbackParameter = aString; - if (!_callbackParameter && [_request URL].indexOf(CPJSONPCallbackReplacementString) < 0) + if (!_callbackParameter && [[_request URL] absoluteString].indexOf(CPJSONPCallbackReplacementString) < 0) [CPException raise:CPInvalidArgumentException reason:@"JSONP source specified without callback parameter or CPJSONPCallbackReplacementString in URL."]; if(shouldStartImmediately) @@ -95,7 +95,7 @@ CPJSONPCallbackReplacementString = @"${JSONP_CALLBACK}"; }; var head = document.getElementsByTagName("head").item(0), - source = [_request URL]; + source = [[_request URL] absoluteString]; if (_callbackParameter) { diff --git a/Foundation/CPURL.j b/Foundation/CPURL.j index 555b0fbcd..14c1d0c5c 100644 --- a/Foundation/CPURL.j +++ b/Foundation/CPURL.j @@ -31,6 +31,8 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; { CPURL _base @accessors(readonly, property=baseURL); CPString _relative @accessors(readonly, property=relativeString); + + CPDictionary _resourceValues; } - (id)initWithScheme:(CPString)scheme host:(CPString)host path:(CPString)path @@ -57,9 +59,13 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; if (!URI_RE.test(URLString)) return nil; - _base = baseURL; - _relative = URLString; - + if (self) + { + _base = baseURL; + _relative = URLString; + _resourceValues = [CPDictionary dictionary]; + } + return self; } @@ -184,6 +190,16 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; return [self absoluteString]; } +- (id)resourceValueForKey:(CPString)aKey +{ + return [_resourceValues objectForKey:aKey]; +} + +- (id)setResourceValue:(id)anObject forKey:(CPString)aKey +{ + [_resourceValues setObject:anObject forKey:aKey]; +} + @end @implementation CPURL (CPCoding) diff --git a/Foundation/CPURLConnection.j b/Foundation/CPURLConnection.j index d1475f18b..dfe8cedbf 100644 --- a/Foundation/CPURLConnection.j +++ b/Foundation/CPURLConnection.j @@ -106,17 +106,17 @@ var CPURLConnectionDelegate = nil; { var request = objj_request_xmlhttp(); - request.open([aRequest HTTPMethod], [aRequest URL], NO); - + request.open([aRequest HTTPMethod], [[aRequest URL] absoluteString], NO); + var fields = [aRequest allHTTPHeaderFields], key = nil, keys = [fields keyEnumerator]; - + while (key = [keys nextObject]) request.setRequestHeader(key, [fields objectForKey:key]); - + request.send([aRequest HTTPBody]); - + return [CPData dataWithString:request.responseText]; } catch (anException) @@ -154,20 +154,21 @@ var CPURLConnectionDelegate = nil; _delegate = aDelegate; _isCanceled = NO; - var path = [_request URL]; - + var URL = [_request URL], + scheme = [URL scheme]; + // Browsers use "file:", Titanium uses "app:" - _isLocalFileConnection = path.indexOf("file:") === 0 || - ((path.indexOf("http:") !== 0 || path.indexOf("https:") !== 0) && + _isLocalFileConnection = scheme === "file" || + ((scheme !== "http" || scheme !== "https:") && window.location && (window.location.protocol === "file:" || window.location.protocol === "app:")); - + _XMLHTTPRequest = objj_request_xmlhttp(); - + if (shouldStartImmediately) [self start]; } - + return self; } @@ -193,7 +194,7 @@ var CPURLConnectionDelegate = nil; try { - _XMLHTTPRequest.open([_request HTTPMethod], [_request URL], YES); + _XMLHTTPRequest.open([_request HTTPMethod], [[_request URL] absoluteString], YES); _XMLHTTPRequest.onreadystatechange = function() { [self _readyStateDidChange]; } diff --git a/Foundation/CPURLRequest.j b/Foundation/CPURLRequest.j index 290d4b26a..a4d7eb136 100644 --- a/Foundation/CPURLRequest.j +++ b/Foundation/CPURLRequest.j @@ -62,7 +62,11 @@ if (self) { - _URL = aURL; + if ([aURL isKindOfClass:[CPString class]]) + _URL = [CPURL URLWithString:aURL]; + else + _URL = aURL; + _HTTPBody = @""; _HTTPMethod = @"GET"; _HTTPHeaderFields = [CPDictionary dictionary]; diff --git a/Foundation/Foundation.j b/Foundation/Foundation.j index a96bc8353..4bf1460e4 100755 --- a/Foundation/Foundation.j +++ b/Foundation/Foundation.j @@ -50,6 +50,7 @@ @import "CPString.j" @import "CPTimer.j" @import "CPUndoManager.j" +@import "CPURL.j" @import "CPURLConnection.j" @import "CPURLRequest.j" @import "CPURLResponse.j"