bug 422537 use a storage stream instead of a pipe as the upload stream when send()ing a document, to follow the expectations of nsIUploadChannel which wants a seekable stream. r+sr=bz a=beltzner

This commit is contained in:
cbiesinger@gmail.com 2008-03-18 12:49:20 -07:00
Родитель 0784293e62
Коммит 4cfd88d15a
3 изменённых файлов: 64 добавлений и 4 удалений

Просмотреть файл

@ -88,6 +88,7 @@
#include "nsWhitespaceTokenizer.h"
#include "nsIMultiPartChannel.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIStorageStream.h"
#define LOAD_STR "load"
#define ERROR_STR "error"
@ -2134,10 +2135,12 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
// Serialize to a stream so that the encoding used will
// match the document's.
nsCOMPtr<nsIInputStream> input;
nsCOMPtr<nsIStorageStream> storStream;
rv = NS_NewStorageStream(4096, PR_UINT32_MAX, getter_AddRefs(storStream));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIOutputStream> output;
rv = NS_NewPipe(getter_AddRefs(input), getter_AddRefs(output),
0, PR_UINT32_MAX);
rv = storStream->GetOutputStream(0, getter_AddRefs(output));
NS_ENSURE_SUCCESS(rv, rv);
// Empty string for encoding means to use document's current
@ -2146,7 +2149,8 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
NS_ENSURE_SUCCESS(rv, rv);
output->Close();
postDataStream = input;
rv = storStream->NewInputStream(0, getter_AddRefs(postDataStream));
NS_ENSURE_SUCCESS(rv, rv);
} else {
// nsISupportsString?
nsCOMPtr<nsISupportsString> wstr(do_QueryInterface(supports));

Просмотреть файл

@ -181,6 +181,7 @@ _TEST_FILES = test_bug5141.html \
test_bug419527.xhtml \
test_bug420609.xhtml \
test_bug420700.html \
test_bug422537.html \
$(NULL)
libs:: $(_TEST_FILES)

Просмотреть файл

@ -0,0 +1,55 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=422537
-->
<head>
<title>Test for bug 422537</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=422537">Mozilla Bug 422537</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 422537 **/
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var isupports_string = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
isupports_string.data = "foo";
const url = "http://localhost:8888";
var body = [
document,
"foo",
isupports_string
];
for each (var i in body) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.send(i);
var chan = xhr.channel;
if (!(chan instanceof Components.interfaces.nsIUploadChannel))
throw "Must be an upload channel";
var stream = chan.uploadStream;
if (!stream || !(stream instanceof Components.interfaces.nsISeekableStream))
throw "Stream must be seekable";
// the following is a no-op, but should not throw an exception
stream.seek(Components.interfaces.nsISeekableStream.NS_SEEK_CUR, 0);
}
</script>
</pre>
</body>
</html>