77 BOOL _isLocalFileConnection;
79 HTTPRequest _HTTPRequest;
82 + (void)setClassDelegate:(
id)delegate
98 var aCFHTTPRequest =
new CFHTTPRequest();
99 aCFHTTPRequest.setWithCredentials([aRequest withCredentials]);
101 aCFHTTPRequest.open([aRequest HTTPMethod], [[aRequest URL] absoluteString], NO);
105 keys = [fields keyEnumerator];
107 while ((key = [keys nextObject]) !== nil)
108 aCFHTTPRequest.setRequestHeader(key, [fields objectForKey:key]);
110 aCFHTTPRequest.send([aRequest HTTPBody]);
112 if (!aCFHTTPRequest.success())
142 - (id)initWithRequest:(
CPURLRequest)aRequest delegate:(
id)aDelegate startImmediately:(BOOL)shouldStartImmediately
149 _originalRequest = [aRequest
copy];
150 _delegate = aDelegate;
153 var URL = [_request URL],
154 scheme = [URL scheme];
157 _isLocalFileConnection = scheme ===
"file" ||
158 ((scheme ===
"http" || scheme ===
"https") &&
160 (window.location.protocol ===
"file:" || window.location.protocol ===
"app:"));
162 _HTTPRequest =
new CFHTTPRequest();
163 _HTTPRequest.setWithCredentials([aRequest withCredentials]);
165 if (shouldStartImmediately)
194 _HTTPRequest.open([_request HTTPMethod], [[_request URL] absoluteString], YES);
196 _HTTPRequest.onreadystatechange =
function() { [
self _readyStateDidChange]; };
198 var fields = [_request allHTTPHeaderFields],
200 keys = [fields keyEnumerator];
202 while ((key = [keys nextObject]) !== nil)
203 _HTTPRequest.setRequestHeader(key, [fields objectForKey:key]);
205 _HTTPRequest.send([_request HTTPBody]);
209 if ([_delegate respondsToSelector:
@selector(connection:didFailWithError:)])
210 [_delegate connection:self didFailWithError:anException];
223 _HTTPRequest.abort();
231 - (BOOL)isLocalFileConnection
233 return _isLocalFileConnection;
237 - (void)_readyStateDidChange
239 if (_HTTPRequest.readyState() === CFHTTPRequest.CompleteState)
241 var statusCode = _HTTPRequest.status(),
242 URL = [_request URL];
244 if (statusCode === 401 && [
CPURLConnectionDelegate respondsToSelector:
@selector(connectionDidReceiveAuthenticationChallenge:)])
248 if ([_delegate respondsToSelector:
@selector(connection:didReceiveResponse:)])
250 if (_isLocalFileConnection)
251 [_delegate connection:self didReceiveResponse:[[
CPURLResponse alloc] initWithURL:URL]];
255 [response _setStatusCode:statusCode];
256 [response _setAllResponseHeaders:_HTTPRequest.getAllResponseHeaders()];
257 [_delegate connection:self didReceiveResponse:response];
263 if ([_delegate respondsToSelector:
@selector(connection:didReceiveData:)])
264 [_delegate connection:self didReceiveData:_HTTPRequest.responseText()];
265 if ([_delegate respondsToSelector:
@selector(connectionDidFinishLoading:)])
266 [_delegate connectionDidFinishLoading:self];
275 - (HTTPRequest)_HTTPRequest
286 _CPReportLenientDeprecation(
self, _cmd,
@selector(sendSynchronousRequest:returningResponse:));
291 - (HTTPRequest)_XMLHTTPRequest
293 _CPReportLenientDeprecation(
self, _cmd,
@selector(_HTTPRequest));
295 return [
self _HTTPRequest];
307 return _originalRequest;