2008-12-27 15:26:55 -08:00
|
|
|
function handleRequest(request, response)
|
|
|
|
{
|
|
|
|
var query = {};
|
|
|
|
request.queryString.split('&').forEach(function (val) {
|
|
|
|
var [name, value] = val.split('=');
|
|
|
|
query[name] = unescape(value);
|
|
|
|
});
|
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
if ("setState" in query) {
|
|
|
|
setState("test/content/base/test_CrossSiteXHR_cache:secData",
|
|
|
|
query.setState);
|
2008-12-27 15:26:55 -08:00
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
response.setHeader("Cache-Control", "no-cache", false);
|
|
|
|
response.setHeader("Content-Type", "text/plain", false);
|
|
|
|
response.write("hi");
|
2008-12-27 15:26:55 -08:00
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
return;
|
|
|
|
}
|
2008-12-27 15:26:55 -08:00
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
var isPreflight = request.method == "OPTIONS";
|
|
|
|
|
|
|
|
// Send response
|
2008-12-27 15:26:55 -08:00
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
secData =
|
|
|
|
eval(getState("test/content/base/test_CrossSiteXHR_cache:secData"));
|
2008-12-27 15:26:55 -08:00
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
if (secData.allowOrigin)
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", secData.allowOrigin);
|
2008-12-27 15:26:55 -08:00
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
if (isPreflight) {
|
2008-12-27 15:26:55 -08:00
|
|
|
if (secData.allowHeaders)
|
|
|
|
response.setHeader("Access-Control-Allow-Headers", secData.allowHeaders);
|
|
|
|
|
|
|
|
if (secData.allowMethods)
|
|
|
|
response.setHeader("Access-Control-Allow-Methods", secData.allowMethods);
|
|
|
|
|
|
|
|
if (secData.cacheTime)
|
|
|
|
response.setHeader("Access-Control-Max-Age", secData.cacheTime.toString());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
response.setHeader("Cache-Control", "no-cache", false);
|
2008-12-27 15:26:55 -08:00
|
|
|
response.setHeader("Content-Type", "application/xml", false);
|
|
|
|
response.write("<res>hello pass</res>\n");
|
|
|
|
}
|