mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-07 01:18:02 +00:00
Change FileRequest to always use CFHTTPRequest and make async/sync configurable. Preparation for "flatten" changes.
This commit is contained in:
1 parent
a08d4c6a06
commit
677cf9e1df
1 file changed
+17
-32
@@ -254,43 +254,28 @@ function determineAndDispatchHTTPRequestEvents(/*CFHTTPRequest*/ aRequest)
|
||||
|
||||
function FileRequest(/*CFURL*/ aURL, onsuccess, onfailure)
|
||||
{
|
||||
#ifdef BROWSER
|
||||
var request = new CFHTTPRequest();
|
||||
|
||||
request.onsuccess = Asynchronous(onsuccess);
|
||||
request.onfailure = Asynchronous(onfailure);
|
||||
|
||||
if (aURL.pathExtension() === "plist")
|
||||
request.overrideMimeType("text/xml");
|
||||
|
||||
request.open("GET", aURL.absoluteString(), YES);
|
||||
if (FileRequest.async)
|
||||
{
|
||||
request.onsuccess = Asynchronous(onsuccess);
|
||||
request.onfailure = Asynchronous(onfailure);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.onsuccess = onsuccess;
|
||||
request.onfailure = onfailure;
|
||||
}
|
||||
|
||||
request.open("GET", aURL.absoluteString(), FileRequest.async);
|
||||
request.send("");
|
||||
}
|
||||
|
||||
#ifdef BROWSER
|
||||
FileRequest.async = YES;
|
||||
#else
|
||||
var FILE = require("file"),
|
||||
filePath = aURL.absoluteURL().path();
|
||||
|
||||
if (!FILE.exists(filePath))
|
||||
return onfailure();
|
||||
|
||||
this._responseText = FILE.read(filePath, { charset:"UTF-8" });
|
||||
|
||||
onsuccess({ type:"success", request:this });
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef COMMONJS
|
||||
FileRequest.prototype.responseText = function()
|
||||
{
|
||||
return this._responseText;
|
||||
}
|
||||
|
||||
FileRequest.prototype.responseXML = function()
|
||||
{
|
||||
return new DOMParser().parseFromString(anXMLString, "text/xml");
|
||||
}
|
||||
|
||||
FileRequest.prototype.responsePropertyList = function()
|
||||
{
|
||||
return CFPropertyList.propertyListFromString(this.responseText());
|
||||
}
|
||||
FileRequest.async = NO;
|
||||
#endif
|
||||
Reference in new issue
Block a user