2014-10-02 17:59:20 +00: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_InternalHeaders_h
|
|
|
|
#define mozilla_dom_InternalHeaders_h
|
|
|
|
|
|
|
|
// needed for HeadersGuardEnum.
|
|
|
|
#include "mozilla/dom/HeadersBinding.h"
|
|
|
|
#include "mozilla/dom/UnionTypes.h"
|
|
|
|
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
template<typename T> class MozMap;
|
2016-06-07 09:46:03 +00:00
|
|
|
class HeadersEntry;
|
2014-10-02 17:59:20 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class InternalHeaders final
|
2014-10-02 17:59:20 +00:00
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalHeaders)
|
|
|
|
|
2014-12-10 06:35:22 +00:00
|
|
|
public:
|
2014-10-02 17:59:20 +00:00
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
Entry(const nsACString& aName, const nsACString& aValue)
|
|
|
|
: mName(aName)
|
|
|
|
, mValue(aValue)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Entry() { }
|
|
|
|
|
|
|
|
nsCString mName;
|
|
|
|
nsCString mValue;
|
|
|
|
};
|
|
|
|
|
2014-12-10 06:35:22 +00:00
|
|
|
private:
|
2014-10-02 17:59:20 +00:00
|
|
|
HeadersGuardEnum mGuard;
|
|
|
|
nsTArray<Entry> mList;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit InternalHeaders(HeadersGuardEnum aGuard = HeadersGuardEnum::None)
|
|
|
|
: mGuard(aGuard)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit InternalHeaders(const InternalHeaders& aOther)
|
2015-10-19 18:23:28 +00:00
|
|
|
: mGuard(HeadersGuardEnum::None)
|
2014-10-02 17:59:20 +00:00
|
|
|
{
|
|
|
|
ErrorResult result;
|
|
|
|
Fill(aOther, result);
|
|
|
|
MOZ_ASSERT(!result.Failed());
|
2015-10-19 18:23:28 +00:00
|
|
|
// Note that it's important to set the guard after Fill(), to make sure
|
|
|
|
// that Fill() doesn't fail if aOther is immutable.
|
|
|
|
mGuard = aOther.mGuard;
|
2014-10-02 17:59:20 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 19:00:15 +00:00
|
|
|
explicit InternalHeaders(const nsTArray<Entry>&& aHeaders,
|
2015-03-02 13:08:00 +00:00
|
|
|
HeadersGuardEnum aGuard = HeadersGuardEnum::None);
|
|
|
|
|
2016-06-07 09:46:03 +00:00
|
|
|
InternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
|
|
|
|
HeadersGuardEnum aGuard);
|
|
|
|
|
|
|
|
void ToIPC(nsTArray<HeadersEntry>& aIPCHeaders,
|
|
|
|
HeadersGuardEnum& aGuard);
|
|
|
|
|
2014-10-02 17:59:20 +00:00
|
|
|
void Append(const nsACString& aName, const nsACString& aValue,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
void Delete(const nsACString& aName, ErrorResult& aRv);
|
2016-10-10 17:20:14 +00:00
|
|
|
void Get(const nsACString& aName, nsACString& aValue, ErrorResult& aRv) const;
|
|
|
|
void GetFirst(const nsACString& aName, nsACString& aValue, ErrorResult& aRv) const;
|
2014-10-02 17:59:20 +00:00
|
|
|
bool Has(const nsACString& aName, ErrorResult& aRv) const;
|
|
|
|
void Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv);
|
|
|
|
|
2015-10-19 17:58:03 +00:00
|
|
|
uint32_t GetIterableLength() const
|
|
|
|
{
|
|
|
|
return mList.Length();
|
|
|
|
}
|
|
|
|
const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex < mList.Length());
|
|
|
|
return NS_ConvertASCIItoUTF16(mList[aIndex].mName);
|
|
|
|
}
|
|
|
|
const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex < mList.Length());
|
|
|
|
return NS_ConvertASCIItoUTF16(mList[aIndex].mValue);
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:59:20 +00:00
|
|
|
void Clear();
|
|
|
|
|
|
|
|
HeadersGuardEnum Guard() const { return mGuard; }
|
|
|
|
void SetGuard(HeadersGuardEnum aGuard, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void Fill(const InternalHeaders& aInit, ErrorResult& aRv);
|
|
|
|
void Fill(const Sequence<Sequence<nsCString>>& aInit, ErrorResult& aRv);
|
|
|
|
void Fill(const MozMap<nsCString>& aInit, ErrorResult& aRv);
|
2014-10-06 18:01:20 +00:00
|
|
|
|
|
|
|
bool HasOnlySimpleHeaders() const;
|
|
|
|
|
2016-03-02 23:09:30 +00:00
|
|
|
bool HasRevalidationHeaders() const;
|
|
|
|
|
2014-10-06 18:01:20 +00:00
|
|
|
static already_AddRefed<InternalHeaders>
|
|
|
|
BasicHeaders(InternalHeaders* aHeaders);
|
|
|
|
|
|
|
|
static already_AddRefed<InternalHeaders>
|
|
|
|
CORSHeaders(InternalHeaders* aHeaders);
|
2014-12-10 06:35:22 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
GetEntries(nsTArray<InternalHeaders::Entry>& aEntries) const;
|
2015-01-07 23:50:54 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
GetUnsafeHeaders(nsTArray<nsCString>& aNames) const;
|
2014-10-02 17:59:20 +00:00
|
|
|
private:
|
|
|
|
virtual ~InternalHeaders();
|
|
|
|
|
|
|
|
static bool IsInvalidName(const nsACString& aName, ErrorResult& aRv);
|
|
|
|
static bool IsInvalidValue(const nsACString& aValue, ErrorResult& aRv);
|
|
|
|
bool IsImmutable(ErrorResult& aRv) const;
|
|
|
|
bool IsForbiddenRequestHeader(const nsACString& aName) const;
|
|
|
|
bool IsForbiddenRequestNoCorsHeader(const nsACString& aName) const;
|
|
|
|
bool IsForbiddenRequestNoCorsHeader(const nsACString& aName,
|
|
|
|
const nsACString& aValue) const;
|
|
|
|
bool IsForbiddenResponseHeader(const nsACString& aName) const;
|
|
|
|
|
|
|
|
bool IsInvalidMutableHeader(const nsACString& aName,
|
|
|
|
ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
return IsInvalidMutableHeader(aName, EmptyCString(), aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsInvalidMutableHeader(const nsACString& aName,
|
|
|
|
const nsACString& aValue,
|
|
|
|
ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
return IsInvalidName(aName, aRv) ||
|
|
|
|
IsInvalidValue(aValue, aRv) ||
|
|
|
|
IsImmutable(aRv) ||
|
|
|
|
IsForbiddenRequestHeader(aName) ||
|
|
|
|
IsForbiddenRequestNoCorsHeader(aName, aValue) ||
|
|
|
|
IsForbiddenResponseHeader(aName);
|
|
|
|
}
|
2015-01-07 23:50:54 +00:00
|
|
|
|
|
|
|
static bool IsSimpleHeader(const nsACString& aName,
|
|
|
|
const nsACString& aValue);
|
2016-03-02 23:09:30 +00:00
|
|
|
|
|
|
|
static bool IsRevalidationHeader(const nsACString& aName);
|
2014-10-02 17:59:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_InternalHeaders_h
|