зеркало из https://github.com/mozilla/gecko-dev.git
Bug 600111 - Throw the correct exceptions in XMLHttpRequest.setRequestHeader(); r=sicking
This commit is contained in:
Родитель
dadd37a9b3
Коммит
921ab270c6
|
@ -3175,15 +3175,21 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable<RequestBody>& aBody)
|
|||
}
|
||||
|
||||
/* void setRequestHeader (in AUTF8String header, in AUTF8String value); */
|
||||
// http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#dom-xmlhttprequest-setrequestheader
|
||||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::SetRequestHeader(const nsACString& header,
|
||||
const nsACString& value)
|
||||
{
|
||||
nsresult rv;
|
||||
// Step 1 and 2
|
||||
if (!(mState & XML_HTTP_REQUEST_OPENED)) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
NS_ASSERTION(mChannel, "mChannel must be valid if we're OPENED.");
|
||||
|
||||
// Step 3
|
||||
// Make sure we don't store an invalid header name in mCORSUnsafeHeaders
|
||||
if (!IsValidHTTPToken(header)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!IsValidHTTPToken(header)) { // XXX nsHttp::IsValidToken?
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
|
||||
// Check that we haven't already opened the channel. We can't rely on
|
||||
|
@ -3191,7 +3197,7 @@ nsXMLHttpRequest::SetRequestHeader(const nsACString& header,
|
|||
// still be waiting for mCORSPreflightChannel to actually open mChannel
|
||||
if (mCORSPreflightChannel) {
|
||||
bool pending;
|
||||
rv = mCORSPreflightChannel->IsPending(&pending);
|
||||
nsresult rv = mCORSPreflightChannel->IsPending(&pending);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (pending) {
|
||||
|
@ -3199,13 +3205,10 @@ nsXMLHttpRequest::SetRequestHeader(const nsACString& header,
|
|||
}
|
||||
}
|
||||
|
||||
if (!(mState & XML_HTTP_REQUEST_OPENED))
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
|
||||
if (!mChannel) // open() initializes mChannel, and open()
|
||||
return NS_ERROR_FAILURE; // must be called before first setRequestHeader()
|
||||
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel);
|
||||
if (!httpChannel) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -3214,12 +3217,11 @@ nsXMLHttpRequest::SetRequestHeader(const nsACString& header,
|
|||
// the executing script has UniversalXPConnect.
|
||||
|
||||
bool privileged;
|
||||
rv = IsCapabilityEnabled("UniversalXPConnect", &privileged);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(IsCapabilityEnabled("UniversalXPConnect", &privileged)))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!privileged) {
|
||||
// Check for dangerous headers
|
||||
// Step 5: Check for dangerous headers.
|
||||
const char *kInvalidHeaders[] = {
|
||||
"accept-charset", "accept-encoding", "access-control-request-headers",
|
||||
"access-control-request-method", "connection", "content-length",
|
||||
|
@ -3264,7 +3266,10 @@ nsXMLHttpRequest::SetRequestHeader(const nsACString& header,
|
|||
}
|
||||
|
||||
// We need to set, not add to, the header.
|
||||
rv = httpChannel->SetRequestHeader(header, value, false);
|
||||
nsresult rv = httpChannel->SetRequestHeader(header, value, false);
|
||||
if (rv == NS_ERROR_INVALID_ARG) {
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// We'll want to duplicate this header for any replacement channels (eg. on redirect)
|
||||
RequestHeader reqHeader = {
|
||||
|
@ -3272,7 +3277,6 @@ nsXMLHttpRequest::SetRequestHeader(const nsACString& header,
|
|||
};
|
||||
mModifiedRequestHeaders.AppendElement(reqHeader);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
MOCHITEST_FILES = \
|
||||
test_interfaces.html.json \
|
||||
test_setrequestheader-invalid-arguments.htm.json \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
{
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 1": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 2": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 3": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 4": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 5": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 6": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 7": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 8": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 9": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 10": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 11": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 12": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 13": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 14": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 15": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 16": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 17": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 18": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 19": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 20": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 21": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 22": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 23": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 24": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 25": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 26": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 27": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 28": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 29": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 30": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 31": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 32": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 33": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 34": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 35": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 36": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 37": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 38": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 39": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 40": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 41": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 42": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 43": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 44": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 45": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 46": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 47": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 48": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 49": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 50": true,
|
||||
"XMLHttpRequest: setRequestHeader() with invalid arguments 51": true
|
||||
}
|
Загрузка…
Ссылка в новой задаче