Commit 2b43a901 authored by ap's avatar ap

Reviewed by Darin.

        - http://bugzilla.opendarwin.org/show_bug.cgi?id=3812
          XMLHttpRequest: PUT, DELETE, HEAD and all other methods but POST actually do a GET.

        HEAD is currently unimplemented because of what seems to be a bug in NSURLConnection,
        and does a GET instead.

WebCore:
        * kwq/KWQKJobClasses.h: Add a method parameter to TransferJob.
        * kwq/KWQKJobClasses.mm:
        (WebCore::TransferJobPrivate::TransferJobPrivate):
        (WebCore::TransferJob::TransferJob):
        (WebCore::TransferJob::method):
        * bridge/mac/WebCoreFrameBridge.h: URL loading functions now take a method parameter.
        * dom/xml_tokenizer.cpp:
        (WebCore::openFunc):
        * khtml/xsl/xslt_processorimpl.cpp:
        (DOM::docLoaderFunc):
        * kwq/KWQLoader.mm:
        (KWQServeRequest):
        (KWQServeSynchronousRequest):
        * loader/loader.cpp:
        (WebCore::Loader::servePendingRequests):
        * page/Frame.cpp:
        (WebCore::Frame::didOpenURL):
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::send): Honor the method passed in open().
        * khtml/ecma/JSXMLHttpRequest.cpp:
        (KJS::JSXMLHttpRequestProtoFunc::callAsFunction): Don't serialize null as "null".

WebKit:
        All WebKit changes are to use the method parameter passed from WebCore.

        * WebCoreSupport/WebFrameBridge.m:
        (-[WebFrameBridge startLoadingResource:withMethod:URL:customHeaders:]):
        (-[WebFrameBridge startLoadingResource:withMethod:URL:customHeaders:postData:]):
        (-[WebFrameBridge syncLoadResourceWithMethod:URL:customHeaders:postData:finalURL:responseHeaders:statusCode:]):
        * WebCoreSupport/WebSubresourceLoader.h:
        * WebCoreSupport/WebSubresourceLoader.m:
        (+[WebSubresourceLoader startLoadingResource:withMethod:URL:customHeaders:referrer:forDataSource:]):
        (+[WebSubresourceLoader startLoadingResource:withMethod:URL:customHeaders:postData:referrer:forDataSource:]):

LayoutTests:
        * http/tests/xmlhttprequest/methods-async-expected.txt: Added.
        * http/tests/xmlhttprequest/methods-async.html: Added.
        * http/tests/xmlhttprequest/methods-expected.txt: Added.
        * http/tests/xmlhttprequest/methods.cgi: Added.
        * http/tests/xmlhttprequest/methods.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@13071 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3166fbf7
2006-03-01 Alexey Proskuryakov <ap@nypop.com>
Reviewed by Darin.
- Tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=3812
XMLHttpRequest: PUT, DELETE, HEAD and all other methods but POST actually do a GET.
* http/tests/xmlhttprequest/methods-async-expected.txt: Added.
* http/tests/xmlhttprequest/methods-async.html: Added.
* http/tests/xmlhttprequest/methods-expected.txt: Added.
* http/tests/xmlhttprequest/methods.cgi: Added.
* http/tests/xmlhttprequest/methods.html: Added.
2006-03-01 Mitz Pettel <opendarwin.org@mitzpettel.com>
Reviewed by Hyatt.
......
Tests for bug 3812 - GET and POST should not be the only HTTP methods implemented in XMLHttpRequest.
GET(""): GET(undefined bytes), Content-Type: undefined
GET(null): GET(undefined bytes), Content-Type: undefined
GET("123"): GET(undefined bytes), Content-Type: undefined
POST(""): POST(0 bytes), Content-Type: application/xml
POST(null): POST(0 bytes), Content-Type: undefined
POST("123"): POST(3 bytes), Content-Type: application/xml
PUT(""): PUT(0 bytes), Content-Type: application/xml
PUT(null): PUT(0 bytes), Content-Type: undefined
PUT("123"): PUT(3 bytes), Content-Type: application/xml
DELETE(""): DELETE(0 bytes), Content-Type: application/xml
DELETE(null): DELETE(0 bytes), Content-Type: undefined
DELETE("123"): DELETE(3 bytes), Content-Type: application/xml
WKFOOBAR(""): WKFOOBAR(0 bytes), Content-Type: application/xml
WKFOOBAR(null): WKFOOBAR(0 bytes), Content-Type: undefined
WKFOOBAR("123"): WKFOOBAR(3 bytes), Content-Type: application/xml
SEARCH(""): SEARCH(0 bytes), Content-Type: application/xml
SEARCH(null): SEARCH(0 bytes), Content-Type: undefined
SEARCH("123"): SEARCH(3 bytes), Content-Type: application/xml
<html>
<body>
<p>Tests for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=3812"> bug 3812</a> -
GET and POST should not be the only HTTP methods implemented in XMLHttpRequest.</p>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
var console_messages = document.createElement("ol");
document.body.appendChild(console_messages);
function log(message)
{
var item = document.createElement("li");
item.appendChild(document.createTextNode(message));
console_messages.appendChild(item);
}
// async
var asyncStep = 1;
req = new XMLHttpRequest;
req.onreadystatechange = processStateChange;
req.open("GET", "methods.cgi", true);
req.send("");
function processStateChange() {
if (req.readyState == 4){
if (req.status == 200){
if (asyncStep == 1) {
asyncStep = 2;
log('GET(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("GET", "methods.cgi", true);
req.send(null);
} else if (asyncStep == 2) {
asyncStep = 3;
log('GET(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("GET", "methods.cgi", true);
req.send("123");
} else if (asyncStep == 3) {
asyncStep = 4;
log('GET("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("POST", "methods.cgi", true);
req.send("");
} else if (asyncStep == 4) {
asyncStep = 5;
log('POST(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("POST", "methods.cgi", true);
req.send(null);
} else if (asyncStep == 5) {
asyncStep = 6;
log('POST(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("POST", "methods.cgi", true);
req.send("123");
} else if (asyncStep == 6) {
asyncStep = 7;
log('POST("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("PUT", "methods.cgi", true);
req.send("");
} else if (asyncStep == 7) {
asyncStep = 8;
log('PUT(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("PUT", "methods.cgi", true);
req.send(null);
} else if (asyncStep == 8) {
asyncStep = 9;
log('PUT(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("PUT", "methods.cgi", true);
req.send("123");
} else if (asyncStep == 9) {
asyncStep = 10;
log('PUT("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("DELETE", "methods.cgi", true);
req.send("");
} else if (asyncStep == 10) {
asyncStep = 11;
log('DELETE(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("DELETE", "methods.cgi", true);
req.send(null);
} else if (asyncStep == 11) {
asyncStep = 15;// 12;
log('DELETE(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("DELETE", "methods.cgi", true);
req.send("123");
} else if (asyncStep == 12) {
asyncStep = 13;
log('DELETE("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("HEAD", "methods.cgi", true);
req.send("");
} else if (asyncStep == 13) {
asyncStep = 14;
log('HEAD(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("HEAD", "methods.cgi", true);
req.send(null);
} else if (asyncStep == 14) {
asyncStep = 15;
log('HEAD(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("HEAD", "methods.cgi", true);
req.send("123");
} else if (asyncStep == 15) {
asyncStep = 16;
log('DELETE("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
//log('HEAD("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("WKFOOBAR", "methods.cgi", true);
req.send("");
} else if (asyncStep == 16) {
asyncStep = 17;
log('WKFOOBAR(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("WKFOOBAR", "methods.cgi", true);
req.send(null);
} else if (asyncStep == 17) {
asyncStep = 18;
log('WKFOOBAR(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("WKFOOBAR", "methods.cgi", true);
req.send("123");
} else if (asyncStep == 18) {
asyncStep = 19;
log('WKFOOBAR("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("SEARCH", "methods.cgi", true);
req.send("");
} else if (asyncStep == 19) {
asyncStep = 20;
log('SEARCH(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("SEARCH", "methods.cgi", true);
req.send(null);
} else if (asyncStep == 20) {
asyncStep = 21;
log('SEARCH(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("SEARCH", "methods.cgi", true);
req.send("123");
} else if (asyncStep == 21) {
log('SEARCH("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
if (window.layoutTestController)
layoutTestController.notifyDone();
}
} else {
log("Error loading URL: status " + req.status);
}
}
}
</script>
</body>
</html>
Tests for bug 3812 - GET and POST should not be the only HTTP methods implemented in XMLHttpRequest.
GET(""): GET(undefined bytes), Content-Type: undefined
GET(null): GET(undefined bytes), Content-Type: undefined
GET("123"): GET(undefined bytes), Content-Type: undefined
POST(""): POST(0 bytes), Content-Type: application/xml
POST(null): POST(0 bytes), Content-Type: undefined
POST("123"): POST(3 bytes), Content-Type: application/xml
PUT(""): PUT(0 bytes), Content-Type: application/xml
PUT(null): PUT(0 bytes), Content-Type: undefined
PUT("123"): PUT(3 bytes), Content-Type: application/xml
DELETE(""): DELETE(0 bytes), Content-Type: application/xml
DELETE(null): DELETE(0 bytes), Content-Type: undefined
DELETE("123"): DELETE(3 bytes), Content-Type: application/xml
WKFOOBAR(""): WKFOOBAR(0 bytes), Content-Type: application/xml
WKFOOBAR(null): WKFOOBAR(0 bytes), Content-Type: undefined
WKFOOBAR("123"): WKFOOBAR(3 bytes), Content-Type: application/xml
SEARCH(""): SEARCH(0 bytes), Content-Type: application/xml
SEARCH(null): SEARCH(0 bytes), Content-Type: undefined
SEARCH("123"): SEARCH(3 bytes), Content-Type: application/xml
#!/usr/bin/perl -w
print "Content-type: text/plain\n";
print "Content-Length: 0\n";
my $cl = $ENV{'CONTENT_LENGTH'};
my $ct = $ENV{'CONTENT_TYPE'};
my $method = $ENV{'REQUEST_METHOD'};
if (defined $cl) {
print "REQLENGTH: $cl\n";
}
if (defined $ct) {
print "REQTYPE: $ct\n";
}
print "REQMETHOD: $method\n";
print "\n";
<html>
<body>
<p>Tests for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=3812"> bug 3812</a> -
GET and POST should not be the only HTTP methods implemented in XMLHttpRequest.</p>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
var console_messages = document.createElement("ol");
document.body.appendChild(console_messages);
function log(message)
{
var item = document.createElement("li");
item.appendChild(document.createTextNode(message));
console_messages.appendChild(item);
}
// sync
req = new XMLHttpRequest;
req.open("GET", "methods.cgi", false);
req.send("");
log('GET(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("GET", "methods.cgi", false);
req.send(null);
log('GET(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("GET", "methods.cgi", false);
req.send("123");
log('GET("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("POST", "methods.cgi", false);
req.send("");
log('POST(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("POST", "methods.cgi", false);
req.send(null);
log('POST(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("POST", "methods.cgi", false);
req.send("123");
log('POST("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("PUT", "methods.cgi", false);
req.send("");
log('PUT(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("PUT", "methods.cgi", false);
req.send(null);
log('PUT(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("PUT", "methods.cgi", false);
req.send("123");
log('PUT("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("DELETE", "methods.cgi", false);
req.send("");
log('DELETE(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("DELETE", "methods.cgi", false);
req.send(null);
log('DELETE(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("DELETE", "methods.cgi", false);
req.send("123");
log('DELETE("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
/*
req.open("HEAD", "methods.cgi", false);
req.send("");
log('HEAD(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("HEAD", "methods.cgi", false);
req.send(null);
log('HEAD(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("HEAD", "methods.cgi", false);
req.send("123");
log('HEAD("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
*/
req.open("WKFOOBAR", "methods.cgi", false);
req.send("");
log('WKFOOBAR(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("WKFOOBAR", "methods.cgi", false);
req.send(null);
log('WKFOOBAR(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("WKFOOBAR", "methods.cgi", false);
req.send("123");
log('WKFOOBAR("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("SEARCH", "methods.cgi", false);
req.send("");
log('SEARCH(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("SEARCH", "methods.cgi", false);
req.send(null);
log('SEARCH(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
req.open("SEARCH", "methods.cgi", false);
req.send("123");
log('SEARCH("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
</script>
</body>
</html>
2006-03-01 Alexey Proskuryakov <ap@nypop.com>
Reviewed by Darin.
- http://bugzilla.opendarwin.org/show_bug.cgi?id=3812
XMLHttpRequest: PUT, DELETE, HEAD and all other methods but POST actually do a GET.
HEAD is currently unimplemented because of what seems to be a bug in NSURLConnection,
and does a GET instead.
* kwq/KWQKJobClasses.h: Add a method parameter to TransferJob.
* kwq/KWQKJobClasses.mm:
(WebCore::TransferJobPrivate::TransferJobPrivate):
(WebCore::TransferJob::TransferJob):
(WebCore::TransferJob::method):
* bridge/mac/WebCoreFrameBridge.h: URL loading functions now take a method parameter.
* dom/xml_tokenizer.cpp:
(WebCore::openFunc):
* khtml/xsl/xslt_processorimpl.cpp:
(DOM::docLoaderFunc):
* kwq/KWQLoader.mm:
(KWQServeRequest):
(KWQServeSynchronousRequest):
* loader/loader.cpp:
(WebCore::Loader::servePendingRequests):
* page/Frame.cpp:
(WebCore::Frame::didOpenURL):
* xml/xmlhttprequest.cpp:
(WebCore::XMLHttpRequest::send): Honor the method passed in open().
* khtml/ecma/JSXMLHttpRequest.cpp:
(KJS::JSXMLHttpRequestProtoFunc::callAsFunction): Don't serialize null as "null".
2006-03-01 Timothy Hatcher <timothy@apple.com>
Reviewed by Darin.
......
......@@ -535,11 +535,11 @@ typedef enum {
- (BOOL)runBeforeUnloadConfirmPanelWithMessage:(NSString *)message;
- (void)addMessageToConsole:(NSDictionary *)message;
- (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)loader withURL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders;
- (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)loader withURL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders postData:(NSArray *)data;
- (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)loader withMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders;
- (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)loader withMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders postData:(NSArray *)data;
- (void)objectLoadedFromCacheWithURL:(NSURL *)URL response:(NSURLResponse *)response data:(NSData *)data;
- (NSData *)syncLoadResourceWithURL:(NSURL *)URL customHeaders:(NSDictionary *)requestHeaders postData:(NSArray *)postData finalURL:(NSURL **)finalNSURL responseHeaders:(NSDictionary **)responseHeaderDict statusCode:(int *)statusCode;
- (NSData *)syncLoadResourceWithMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)requestHeaders postData:(NSArray *)postData finalURL:(NSURL **)finalNSURL responseHeaders:(NSDictionary **)responseHeaderDict statusCode:(int *)statusCode;
- (BOOL)isReloading;
- (time_t)expiresTimeForResponse:(NSURLResponse *)response;
......
......@@ -181,7 +181,7 @@ static void* openFunc(const char* uri)
return &globalDescriptor;
KURL finalURL;
TransferJob* job = new TransferJob(0, uri);
TransferJob* job = new TransferJob(0, "GET", uri);
QString headers;
ByteArray data = KWQServeSynchronousRequest(Cache::loader(), globalDocLoader, job, finalURL, headers);
......
......@@ -222,8 +222,10 @@ JSValue* JSXMLHttpRequestProtoFunc::callAsFunction(ExecState *exec, JSObject* th
body = doc->toString().qstring();
} else {
// converting certain values (like null) to object can set an exception
exec->clearException();
body = args[0]->toString(exec).domString();
if (exec->hadException())
exec->clearException();
else
body = args[0]->toString(exec).domString();
}
}
......
......@@ -88,7 +88,7 @@ static xmlDocPtr docLoaderFunc(const xmlChar *uri,
KURL url((const char*)base, (const char*)uri);
xmlFree(base);
KURL finalURL;
TransferJob* job = new TransferJob(0, url);
TransferJob* job = new TransferJob(0, "GET", url);
QString headers;
xmlGenericErrorFunc oldErrorFunc = xmlGenericError;
void *oldErrorContext = xmlGenericErrorContext;
......
......@@ -47,8 +47,8 @@ class TransferJobPrivate;
class TransferJob {
public:
TransferJob(TransferJobClient*, const KURL&);
TransferJob(TransferJobClient*, const KURL&, const FormData& postData);
TransferJob(TransferJobClient*, const String& method, const KURL&);
TransferJob(TransferJobClient*, const String& method, const KURL&, const FormData& postData);
~TransferJob();
int error() const;
......@@ -61,7 +61,7 @@ public:
void kill();
KURL url() const;
QString method() const;
String method() const;
FormData postData() const;
#if __APPLE__
......
......@@ -44,26 +44,26 @@ namespace WebCore {
class TransferJobPrivate
{
public:
TransferJobPrivate(TransferJobClient* c, const KURL& u)
TransferJobPrivate(TransferJobClient* c, const String& method, const KURL& u)
: client(c)
, status(0)
, metaData(KWQRetainNSRelease([[NSMutableDictionary alloc] initWithCapacity:17]))
, URL(u)
, loader(nil)
, method("GET")
, method(method)
, response(nil)
, assembledResponseHeaders(true)
, retrievedCharset(true)
{
}
TransferJobPrivate(TransferJobClient* c, const KURL& u, const FormData& p)
TransferJobPrivate(TransferJobClient* c, const String& method, const KURL& u, const FormData& p)
: client(c)
, status(0)
, metaData(KWQRetainNSRelease([[NSMutableDictionary alloc] initWithCapacity:17]))
, URL(u)
, loader(nil)
, method("POST")
, method(method)
, postData(p)
, response(nil)
, assembledResponseHeaders(true)
......@@ -84,7 +84,7 @@ public:
NSMutableDictionary* metaData;
KURL URL;
KWQResourceLoader* loader;
QString method;
String method;
FormData postData;
NSURLResponse* response;
......@@ -93,13 +93,13 @@ public:
QString responseHeaders;
};
TransferJob::TransferJob(TransferJobClient* client, const KURL& url)
: d(new TransferJobPrivate(client, url))
TransferJob::TransferJob(TransferJobClient* client, const String& method, const KURL& url)
: d(new TransferJobPrivate(client, method, url))
{
}
TransferJob::TransferJob(TransferJobClient* client, const KURL& url, const FormData& postData)
: d(new TransferJobPrivate(client, url, postData))
TransferJob::TransferJob(TransferJobClient* client, const String& method, const KURL& url, const FormData& postData)
: d(new TransferJobPrivate(client, method, url, postData))
{
}
......@@ -211,7 +211,7 @@ FormData TransferJob::postData() const
return d->postData;
}
QString TransferJob::method() const
String TransferJob::method() const
{
return d->method;
}
......
......@@ -131,11 +131,11 @@ bool KWQServeRequest(Loader *loader, DocLoader *docLoader, TransferJob *job)
headerDict = [NSDictionary _webcore_dictionaryWithHeaderString:headerString.getNSString()];
}
if (job->method() == "POST") {
handle = [bridge startLoadingResource:resourceLoader withURL:job->url().getNSURL() customHeaders:headerDict
if (job->postData().count() > 0) {
handle = [bridge startLoadingResource:resourceLoader withMethod:job->method() URL:job->url().getNSURL() customHeaders:headerDict
postData:arrayFromFormData(job->postData())];
} else {
handle = [bridge startLoadingResource:resourceLoader withURL:job->url().getNSURL() customHeaders:headerDict];
handle = [bridge startLoadingResource:resourceLoader withMethod:job->method() URL:job->url().getNSURL() customHeaders:headerDict];
}
[resourceLoader setHandle:handle];
[resourceLoader release];
......@@ -190,14 +190,13 @@ ByteArray KWQServeSynchronousRequest(Loader *loader, DocLoader *docLoader, Trans
}
NSArray *postData = nil;
if (job->method() == "POST") {
if (job->postData().count() > 0)
postData = arrayFromFormData(job->postData());
}
NSURL *finalNSURL = nil;
NSDictionary *responseHeaderDict = nil;
int statusCode = 0;
NSData *resultData = [bridge syncLoadResourceWithURL:job->url().getNSURL() customHeaders:headerDict postData:postData finalURL:&finalNSURL responseHeaders:&responseHeaderDict statusCode:&statusCode];
NSData *resultData = [bridge syncLoadResourceWithMethod:job->method() URL:job->url().getNSURL() customHeaders:headerDict postData:postData finalURL:&finalNSURL responseHeaders:&responseHeaderDict statusCode:&statusCode];
[headerDict release];
job->kill();
......
......@@ -93,7 +93,7 @@ void Loader::servePendingRequests()
Request *req = m_requestsPending.take(0);
KURL u(req->object->url().qstring());
TransferJob* job = new TransferJob(this, u);
TransferJob* job = new TransferJob(this, "GET", u);
if (!req->object->accept().isEmpty())
job->addMetaData("accept", req->object->accept());
......
......@@ -225,10 +225,10 @@ bool Frame::didOpenURL(const KURL &url)
d->m_cachePolicy = KIO::CC_Verify;
if (args.doPost() && url.protocol().startsWith("http")) {
d->m_job = new TransferJob(this, url, args.postData);
d->m_job = new TransferJob(this, "POST", url, args.postData);
d->m_job->addMetaData("content-type", args.contentType() );
} else
d->m_job = new TransferJob(this, url);
d->m_job = new TransferJob(this, "GET", url);
d->m_job->addMetaData(args.metaData());
......
......@@ -240,7 +240,7 @@ void XMLHttpRequest::send(const DOMString& _body)
aborted = false;
if (method.lower() == "post" && (url.protocol().lower() == "http" || url.protocol().lower() == "https") ) {
if (!_body.isNull() && method.lower() != "get" && method.lower() != "head" && (url.protocol().lower() == "http" || url.protocol().lower() == "https")) {
QString contentType = getRequestHeader("Content-Type");
QString charset;
if (contentType.isEmpty())
......@@ -255,10 +255,15 @@ void XMLHttpRequest::send(const DOMString& _body)
if (!encoding.isValid()) // FIXME: report an error?
encoding = TextEncoding(UTF8Encoding);
job = new TransferJob(async ? this : 0, url, encoding.fromUnicode(_body.qstring()));
job = new TransferJob(async ? this : 0, method, url, encoding.fromUnicode(_body.qstring()));
} else {