mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1526322 - Ensure GeckoWebExecutor doesn't clobber the Content-Type header. r=csadilek
Differential Revision: https://phabricator.services.mozilla.com/D19506 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
4c0cf6db45
commit
1e0e61116d
@ -107,6 +107,7 @@ class WebExecutorTest {
|
||||
.addHeader("Header2", "Value1")
|
||||
.addHeader("Header2", "Value2")
|
||||
.referrer(referrer)
|
||||
.header("Content-Type", "text/plain")
|
||||
.body(bodyString.toDirectByteBuffer())
|
||||
.build()
|
||||
|
||||
@ -121,6 +122,7 @@ class WebExecutorTest {
|
||||
assertThat("Method should match", body.getString("method"), equalTo("POST"))
|
||||
assertThat("Headers should match", body.getJSONObject("headers").getString("Header1"), equalTo("Value"))
|
||||
assertThat("Headers should match", body.getJSONObject("headers").getString("Header2"), equalTo("Value1, Value2"))
|
||||
assertThat("Headers should match", body.getJSONObject("headers").getString("Content-Type"), equalTo("text/plain"))
|
||||
assertThat("Referrer should match", body.getJSONObject("headers").getString("Referer"), equalTo(referrer))
|
||||
assertThat("Data should match", body.getString("data"), equalTo(bodyString));
|
||||
}
|
||||
|
@ -362,14 +362,19 @@ nsresult WebExecutorSupport::CreateStreamLoader(
|
||||
// Headers
|
||||
const auto keys = reqBase->GetHeaderKeys();
|
||||
const auto values = reqBase->GetHeaderValues();
|
||||
auto contentType = EmptyCString();
|
||||
for (size_t i = 0; i < keys->Length(); i++) {
|
||||
const auto key = jni::String::LocalRef(keys->GetElement(i));
|
||||
const auto value = jni::String::LocalRef(values->GetElement(i));
|
||||
const auto key = jni::String::LocalRef(keys->GetElement(i))->ToCString();
|
||||
const auto value =
|
||||
jni::String::LocalRef(values->GetElement(i))->ToCString();
|
||||
|
||||
if (key.LowerCaseEqualsASCII("content-type")) {
|
||||
contentType = value;
|
||||
}
|
||||
|
||||
// We clobber any duplicate keys here because we've already merged them
|
||||
// in the upstream WebRequest.
|
||||
rv = httpChannel->SetRequestHeader(key->ToCString(), value->ToCString(),
|
||||
false /* merge */);
|
||||
rv = httpChannel->SetRequestHeader(key, value, false /* merge */);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
@ -382,7 +387,7 @@ nsresult WebExecutorSupport::CreateStreamLoader(
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = uploadChannel->ExplicitSetUploadStream(
|
||||
stream, EmptyCString(), -1, aRequest->Method()->ToCString(), false);
|
||||
stream, contentType, -1, aRequest->Method()->ToCString(), false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user