2014-10-02 21:59:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/InternalHeaders.h"
|
|
|
|
|
2016-06-07 12:46:03 +03:00
|
|
|
#include "mozilla/dom/FetchTypes.h"
|
2014-10-02 21:59:20 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
|
|
#include "nsContentUtils.h"
|
2017-02-14 18:06:39 +03:00
|
|
|
#include "nsIHttpHeaderVisitor.h"
|
2014-10-02 21:59:20 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
InternalHeaders::InternalHeaders(const nsTArray<Entry>&& aHeaders,
|
2015-03-02 16:08:00 +03:00
|
|
|
HeadersGuardEnum aGuard)
|
|
|
|
: mGuard(aGuard)
|
2015-04-16 22:00:15 +03:00
|
|
|
, mList(aHeaders)
|
2017-09-17 12:18:20 +03:00
|
|
|
, mListDirty(true)
|
2015-03-02 16:08:00 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:46:03 +03:00
|
|
|
InternalHeaders::InternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
|
|
|
|
HeadersGuardEnum aGuard)
|
|
|
|
: mGuard(aGuard)
|
2017-09-17 12:18:20 +03:00
|
|
|
, mListDirty(true)
|
2016-06-07 12:46:03 +03:00
|
|
|
{
|
|
|
|
for (const HeadersEntry& headersEntry : aHeadersEntryList) {
|
|
|
|
mList.AppendElement(Entry(headersEntry.name(), headersEntry.value()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::ToIPC(nsTArray<HeadersEntry>& aIPCHeaders,
|
|
|
|
HeadersGuardEnum& aGuard)
|
|
|
|
{
|
|
|
|
aGuard = mGuard;
|
|
|
|
|
|
|
|
aIPCHeaders.Clear();
|
|
|
|
for (Entry& entry : mList) {
|
|
|
|
aIPCHeaders.AppendElement(HeadersEntry(entry.mName, entry.mValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
void
|
|
|
|
InternalHeaders::Append(const nsACString& aName, const nsACString& aValue,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsAutoCString lowerName;
|
|
|
|
ToLowerCase(aName, lowerName);
|
2017-04-10 11:15:29 +03:00
|
|
|
nsAutoCString trimValue;
|
|
|
|
NS_TrimHTTPWhitespace(aValue, trimValue);
|
2014-10-02 21:59:20 +04:00
|
|
|
|
2017-04-10 11:15:29 +03:00
|
|
|
if (IsInvalidMutableHeader(lowerName, trimValue, aRv)) {
|
2014-10-02 21:59:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-17 12:18:20 +03:00
|
|
|
SetListDirty();
|
|
|
|
|
2017-04-10 11:15:29 +03:00
|
|
|
mList.AppendElement(Entry(lowerName, trimValue));
|
2014-10-02 21:59:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::Delete(const nsACString& aName, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsAutoCString lowerName;
|
|
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
|
|
|
|
if (IsInvalidMutableHeader(lowerName, aRv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-17 12:18:20 +03:00
|
|
|
SetListDirty();
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
// remove in reverse order to minimize copying
|
|
|
|
for (int32_t i = mList.Length() - 1; i >= 0; --i) {
|
|
|
|
if (lowerName == mList[i].mName) {
|
|
|
|
mList.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-10 20:20:14 +03:00
|
|
|
InternalHeaders::Get(const nsACString& aName, nsACString& aValue, ErrorResult& aRv) const
|
2014-10-02 21:59:20 +04:00
|
|
|
{
|
|
|
|
nsAutoCString lowerName;
|
|
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
|
|
|
|
if (IsInvalidName(lowerName, aRv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-07 10:33:38 +03:00
|
|
|
const char* delimiter = ", ";
|
2016-10-10 20:20:14 +03:00
|
|
|
bool firstValueFound = false;
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
|
|
if (lowerName == mList[i].mName) {
|
2016-10-10 20:20:14 +03:00
|
|
|
if (firstValueFound) {
|
|
|
|
aValue += delimiter;
|
|
|
|
}
|
|
|
|
aValue += mList[i].mValue;
|
|
|
|
firstValueFound = true;
|
2014-10-02 21:59:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No value found, so return null to content
|
2016-10-10 20:20:14 +03:00
|
|
|
if (!firstValueFound) {
|
|
|
|
aValue.SetIsVoid(true);
|
|
|
|
}
|
2014-10-02 21:59:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-10 20:20:14 +03:00
|
|
|
InternalHeaders::GetFirst(const nsACString& aName, nsACString& aValue, ErrorResult& aRv) const
|
2014-10-02 21:59:20 +04:00
|
|
|
{
|
|
|
|
nsAutoCString lowerName;
|
|
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
|
|
|
|
if (IsInvalidName(lowerName, aRv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
|
|
if (lowerName == mList[i].mName) {
|
2016-10-10 20:20:14 +03:00
|
|
|
aValue = mList[i].mValue;
|
|
|
|
return;
|
2014-10-02 21:59:20 +04:00
|
|
|
}
|
|
|
|
}
|
2016-10-10 20:20:14 +03:00
|
|
|
|
|
|
|
// No value found, so return null to content
|
|
|
|
aValue.SetIsVoid(true);
|
2014-10-02 21:59:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InternalHeaders::Has(const nsACString& aName, ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
nsAutoCString lowerName;
|
|
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
|
|
|
|
if (IsInvalidName(lowerName, aRv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
|
|
if (lowerName == mList[i].mName) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsAutoCString lowerName;
|
|
|
|
ToLowerCase(aName, lowerName);
|
2017-04-10 11:15:29 +03:00
|
|
|
nsAutoCString trimValue;
|
|
|
|
NS_TrimHTTPWhitespace(aValue, trimValue);
|
2014-10-02 21:59:20 +04:00
|
|
|
|
2017-04-10 11:15:29 +03:00
|
|
|
if (IsInvalidMutableHeader(lowerName, trimValue, aRv)) {
|
2014-10-02 21:59:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-17 12:18:20 +03:00
|
|
|
SetListDirty();
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
int32_t firstIndex = INT32_MAX;
|
|
|
|
|
|
|
|
// remove in reverse order to minimize copying
|
|
|
|
for (int32_t i = mList.Length() - 1; i >= 0; --i) {
|
|
|
|
if (lowerName == mList[i].mName) {
|
|
|
|
firstIndex = std::min(firstIndex, i);
|
|
|
|
mList.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firstIndex < INT32_MAX) {
|
|
|
|
Entry* entry = mList.InsertElementAt(firstIndex);
|
|
|
|
entry->mName = lowerName;
|
2017-04-10 11:15:29 +03:00
|
|
|
entry->mValue = trimValue;
|
2014-10-02 21:59:20 +04:00
|
|
|
} else {
|
2017-04-10 11:15:29 +03:00
|
|
|
mList.AppendElement(Entry(lowerName, trimValue));
|
2014-10-02 21:59:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::Clear()
|
|
|
|
{
|
2017-09-17 12:18:20 +03:00
|
|
|
SetListDirty();
|
2014-10-02 21:59:20 +04:00
|
|
|
mList.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::SetGuard(HeadersGuardEnum aGuard, ErrorResult& aRv)
|
|
|
|
{
|
2015-10-27 19:23:34 +03:00
|
|
|
// The guard is only checked during ::Set() and ::Append() in the spec. It
|
|
|
|
// does not require revalidating headers already set.
|
2014-10-02 21:59:20 +04:00
|
|
|
mGuard = aGuard;
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalHeaders::~InternalHeaders()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsSimpleHeader(const nsACString& aName, const nsACString& aValue)
|
|
|
|
{
|
|
|
|
// Note, we must allow a null content-type value here to support
|
|
|
|
// get("content-type"), but the IsInvalidValue() check will prevent null
|
|
|
|
// from being set or appended.
|
|
|
|
return aName.EqualsLiteral("accept") ||
|
|
|
|
aName.EqualsLiteral("accept-language") ||
|
|
|
|
aName.EqualsLiteral("content-language") ||
|
|
|
|
(aName.EqualsLiteral("content-type") &&
|
|
|
|
nsContentUtils::IsAllowedNonCorsContentType(aValue));
|
|
|
|
}
|
|
|
|
|
2016-03-03 02:09:30 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsRevalidationHeader(const nsACString& aName)
|
|
|
|
{
|
|
|
|
return aName.EqualsLiteral("if-modified-since") ||
|
|
|
|
aName.EqualsLiteral("if-none-match") ||
|
|
|
|
aName.EqualsLiteral("if-unmodified-since") ||
|
|
|
|
aName.EqualsLiteral("if-match") ||
|
|
|
|
aName.EqualsLiteral("if-range");
|
|
|
|
}
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
//static
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsInvalidName(const nsACString& aName, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!NS_IsValidHTTPToken(aName)) {
|
|
|
|
NS_ConvertUTF8toUTF16 label(aName);
|
2015-11-20 21:36:46 +03:00
|
|
|
aRv.ThrowTypeError<MSG_INVALID_HEADER_NAME>(label);
|
2014-10-02 21:59:20 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsInvalidValue(const nsACString& aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!NS_IsReasonableHTTPHeaderValue(aValue)) {
|
|
|
|
NS_ConvertUTF8toUTF16 label(aValue);
|
2015-11-20 21:36:46 +03:00
|
|
|
aRv.ThrowTypeError<MSG_INVALID_HEADER_VALUE>(label);
|
2014-10-02 21:59:20 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsImmutable(ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
if (mGuard == HeadersGuardEnum::Immutable) {
|
2015-10-05 19:38:14 +03:00
|
|
|
aRv.ThrowTypeError<MSG_HEADERS_IMMUTABLE>();
|
2014-10-02 21:59:20 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsForbiddenRequestHeader(const nsACString& aName) const
|
|
|
|
{
|
|
|
|
return mGuard == HeadersGuardEnum::Request &&
|
|
|
|
nsContentUtils::IsForbiddenRequestHeader(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsForbiddenRequestNoCorsHeader(const nsACString& aName) const
|
|
|
|
{
|
|
|
|
return mGuard == HeadersGuardEnum::Request_no_cors &&
|
|
|
|
!IsSimpleHeader(aName, EmptyCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsForbiddenRequestNoCorsHeader(const nsACString& aName,
|
|
|
|
const nsACString& aValue) const
|
|
|
|
{
|
|
|
|
return mGuard == HeadersGuardEnum::Request_no_cors &&
|
|
|
|
!IsSimpleHeader(aName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InternalHeaders::IsForbiddenResponseHeader(const nsACString& aName) const
|
|
|
|
{
|
|
|
|
return mGuard == HeadersGuardEnum::Response &&
|
|
|
|
nsContentUtils::IsForbiddenResponseHeader(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::Fill(const InternalHeaders& aInit, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
const nsTArray<Entry>& list = aInit.mList;
|
|
|
|
for (uint32_t i = 0; i < list.Length() && !aRv.Failed(); ++i) {
|
|
|
|
const Entry& entry = list[i];
|
|
|
|
Append(entry.mName, entry.mValue, aRv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::Fill(const Sequence<Sequence<nsCString>>& aInit, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < aInit.Length() && !aRv.Failed(); ++i) {
|
|
|
|
const Sequence<nsCString>& tuple = aInit[i];
|
|
|
|
if (tuple.Length() != 2) {
|
2015-10-05 19:38:14 +03:00
|
|
|
aRv.ThrowTypeError<MSG_INVALID_HEADER_SEQUENCE>();
|
2014-10-02 21:59:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Append(tuple[0], tuple[1], aRv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-15 08:01:35 +03:00
|
|
|
InternalHeaders::Fill(const Record<nsCString, nsCString>& aInit, ErrorResult& aRv)
|
2014-10-02 21:59:20 +04:00
|
|
|
{
|
2017-02-15 08:00:00 +03:00
|
|
|
for (auto& entry : aInit.Entries()) {
|
2017-02-15 08:01:39 +03:00
|
|
|
Append(entry.mKey, entry.mValue, aRv);
|
2017-02-15 08:00:00 +03:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-02 21:59:20 +04:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 22:01:20 +04:00
|
|
|
|
2017-02-14 18:06:39 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class FillHeaders final : public nsIHttpHeaderVisitor
|
|
|
|
{
|
|
|
|
RefPtr<InternalHeaders> mInternalHeaders;
|
|
|
|
|
|
|
|
~FillHeaders() = default;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
explicit FillHeaders(InternalHeaders* aInternalHeaders)
|
|
|
|
: mInternalHeaders(aInternalHeaders)
|
|
|
|
{
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mInternalHeaders);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
VisitHeader(const nsACString& aHeader, const nsACString& aValue) override
|
|
|
|
{
|
2018-02-01 22:21:14 +03:00
|
|
|
mInternalHeaders->Append(aHeader, aValue, IgnoreErrors());
|
2017-02-14 18:06:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(FillHeaders, nsIHttpHeaderVisitor)
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::FillResponseHeaders(nsIRequest* aRequest)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest);
|
|
|
|
if (!httpChannel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<FillHeaders> visitor = new FillHeaders(this);
|
2016-12-20 06:49:32 +03:00
|
|
|
nsresult rv = httpChannel->VisitResponseHeaders(visitor);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("failed to fill headers");
|
|
|
|
}
|
2017-02-14 18:06:39 +03:00
|
|
|
}
|
|
|
|
|
2014-10-06 22:01:20 +04:00
|
|
|
bool
|
|
|
|
InternalHeaders::HasOnlySimpleHeaders() const
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
|
|
if (!IsSimpleHeader(mList[i].mName, mList[i].mValue)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-03 02:09:30 +03:00
|
|
|
bool
|
|
|
|
InternalHeaders::HasRevalidationHeaders() const
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
|
|
if (IsRevalidationHeader(mList[i].mName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-06 22:01:20 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<InternalHeaders>
|
|
|
|
InternalHeaders::BasicHeaders(InternalHeaders* aHeaders)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InternalHeaders> basic = new InternalHeaders(*aHeaders);
|
2014-10-06 22:01:20 +04:00
|
|
|
ErrorResult result;
|
|
|
|
// The Set-Cookie headers cannot be invalid mutable headers, so the Delete
|
|
|
|
// must succeed.
|
|
|
|
basic->Delete(NS_LITERAL_CSTRING("Set-Cookie"), result);
|
|
|
|
MOZ_ASSERT(!result.Failed());
|
|
|
|
basic->Delete(NS_LITERAL_CSTRING("Set-Cookie2"), result);
|
|
|
|
MOZ_ASSERT(!result.Failed());
|
|
|
|
return basic.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<InternalHeaders>
|
|
|
|
InternalHeaders::CORSHeaders(InternalHeaders* aHeaders)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InternalHeaders> cors = new InternalHeaders(aHeaders->mGuard);
|
2014-10-06 22:01:20 +04:00
|
|
|
ErrorResult result;
|
|
|
|
|
2015-01-08 02:50:54 +03:00
|
|
|
nsAutoCString acExposedNames;
|
2016-10-10 20:20:14 +03:00
|
|
|
aHeaders->GetFirst(NS_LITERAL_CSTRING("Access-Control-Expose-Headers"), acExposedNames, result);
|
2014-10-06 22:01:20 +04:00
|
|
|
MOZ_ASSERT(!result.Failed());
|
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsCString, 5> exposeNamesArray;
|
2015-01-08 02:50:54 +03:00
|
|
|
nsCCharSeparatedTokenizer exposeTokens(acExposedNames, ',');
|
|
|
|
while (exposeTokens.hasMoreTokens()) {
|
|
|
|
const nsDependentCSubstring& token = exposeTokens.nextToken();
|
|
|
|
if (token.IsEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NS_IsValidHTTPToken(token)) {
|
|
|
|
NS_WARNING("Got invalid HTTP token in Access-Control-Expose-Headers. Header value is:");
|
|
|
|
NS_WARNING(acExposedNames.get());
|
|
|
|
exposeNamesArray.Clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
exposeNamesArray.AppendElement(token);
|
|
|
|
}
|
|
|
|
|
2014-10-06 22:01:20 +04:00
|
|
|
nsCaseInsensitiveCStringArrayComparator comp;
|
|
|
|
for (uint32_t i = 0; i < aHeaders->mList.Length(); ++i) {
|
|
|
|
const Entry& entry = aHeaders->mList[i];
|
|
|
|
if (entry.mName.EqualsASCII("cache-control") ||
|
|
|
|
entry.mName.EqualsASCII("content-language") ||
|
|
|
|
entry.mName.EqualsASCII("content-type") ||
|
|
|
|
entry.mName.EqualsASCII("expires") ||
|
|
|
|
entry.mName.EqualsASCII("last-modified") ||
|
|
|
|
entry.mName.EqualsASCII("pragma") ||
|
2015-01-08 02:50:54 +03:00
|
|
|
exposeNamesArray.Contains(entry.mName, comp)) {
|
2014-10-06 22:01:20 +04:00
|
|
|
cors->Append(entry.mName, entry.mValue, result);
|
|
|
|
MOZ_ASSERT(!result.Failed());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cors.forget();
|
|
|
|
}
|
2014-12-10 09:35:22 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::GetEntries(nsTArray<InternalHeaders::Entry>& aEntries) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aEntries.IsEmpty());
|
|
|
|
aEntries.AppendElements(mList);
|
|
|
|
}
|
2015-01-08 02:50:54 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::GetUnsafeHeaders(nsTArray<nsCString>& aNames) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNames.IsEmpty());
|
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
|
|
const Entry& header = mList[i];
|
|
|
|
if (!InternalHeaders::IsSimpleHeader(header.mName, header.mValue)) {
|
|
|
|
aNames.AppendElement(header.mName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2017-09-17 12:18:20 +03:00
|
|
|
void
|
|
|
|
InternalHeaders::MaybeSortList()
|
|
|
|
{
|
|
|
|
class Comparator {
|
|
|
|
public:
|
|
|
|
bool Equals(const Entry& aA, const Entry& aB) const
|
|
|
|
{
|
|
|
|
return aA.mName == aB.mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LessThan(const Entry& aA, const Entry& aB) const
|
|
|
|
{
|
|
|
|
return aA.mName < aB.mName;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!mListDirty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mListDirty = false;
|
|
|
|
|
|
|
|
Comparator comparator;
|
|
|
|
|
|
|
|
mSortedList.Clear();
|
|
|
|
for (const Entry& entry : mList) {
|
|
|
|
bool found = false;
|
|
|
|
for (Entry& sortedEntry : mSortedList) {
|
|
|
|
if (sortedEntry.mName == entry.mName) {
|
|
|
|
sortedEntry.mValue += ", ";
|
|
|
|
sortedEntry.mValue += entry.mValue;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
mSortedList.InsertElementSorted(entry, comparator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InternalHeaders::SetListDirty()
|
|
|
|
{
|
|
|
|
mSortedList.Clear();
|
|
|
|
mListDirty = true;
|
|
|
|
}
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|