1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_Headers_h
8 #define mozilla_dom_Headers_h
10 #include "mozilla/dom/HeadersBinding.h"
12 #include "nsClassHashtable.h"
13 #include "nsWrapperCache.h"
15 #include "InternalHeaders.h"
23 template <typename K
, typename V
>
25 class ByteStringSequenceSequenceOrByteStringByteStringRecord
;
26 class OwningByteStringSequenceSequenceOrByteStringByteStringRecord
;
29 * This Headers class is only used to represent the content facing Headers
30 * object. It is actually backed by an InternalHeaders implementation. Gecko
31 * code should NEVER use this, except in the Request and Response
32 * implementations, where they must always be created from the backing
33 * InternalHeaders object.
35 class Headers final
: public nsISupports
, public nsWrapperCache
{
36 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
37 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Headers
)
40 friend class Response
;
43 nsCOMPtr
<nsISupports
> mOwner
;
44 RefPtr
<InternalHeaders
> mInternalHeaders
;
47 explicit Headers(nsISupports
* aOwner
, InternalHeaders
* aInternalHeaders
)
48 : mOwner(aOwner
), mInternalHeaders(aInternalHeaders
) {}
50 explicit Headers(const Headers
& aOther
) = delete;
52 static bool PrefEnabled(JSContext
* cx
, JSObject
* obj
);
54 static already_AddRefed
<Headers
> Constructor(
55 const GlobalObject
& aGlobal
,
56 const Optional
<ByteStringSequenceSequenceOrByteStringByteStringRecord
>&
60 static already_AddRefed
<Headers
> Constructor(
61 const GlobalObject
& aGlobal
,
62 const OwningByteStringSequenceSequenceOrByteStringByteStringRecord
& aInit
,
65 static already_AddRefed
<Headers
> Create(
66 nsIGlobalObject
* aGlobalObject
,
67 const OwningByteStringSequenceSequenceOrByteStringByteStringRecord
& aInit
,
70 void Append(const nsACString
& aName
, const nsACString
& aValue
,
72 mInternalHeaders
->Append(aName
, aValue
, aRv
);
75 void Delete(const nsACString
& aName
, ErrorResult
& aRv
) {
76 mInternalHeaders
->Delete(aName
, aRv
);
79 void Get(const nsACString
& aName
, nsACString
& aValue
,
80 ErrorResult
& aRv
) const {
81 mInternalHeaders
->Get(aName
, aValue
, aRv
);
84 void GetSetCookie(nsTArray
<nsCString
>& aValues
) const {
85 mInternalHeaders
->GetSetCookie(aValues
);
88 void GetFirst(const nsACString
& aName
, nsACString
& aValue
,
89 ErrorResult
& aRv
) const {
90 mInternalHeaders
->GetFirst(aName
, aValue
, aRv
);
93 bool Has(const nsACString
& aName
, ErrorResult
& aRv
) const {
94 return mInternalHeaders
->Has(aName
, aRv
);
97 void Set(const nsACString
& aName
, const nsACString
& aValue
,
99 mInternalHeaders
->Set(aName
, aValue
, aRv
);
102 uint32_t GetIterableLength() const {
103 return mInternalHeaders
->GetIterableLength();
105 const nsString
GetKeyAtIndex(unsigned aIndex
) const {
106 return mInternalHeaders
->GetKeyAtIndex(aIndex
);
108 const nsString
GetValueAtIndex(unsigned aIndex
) const {
109 return mInternalHeaders
->GetValueAtIndex(aIndex
);
113 HeadersGuardEnum
Guard() const { return mInternalHeaders
->Guard(); }
115 void SetGuard(HeadersGuardEnum aGuard
, ErrorResult
& aRv
) {
116 mInternalHeaders
->SetGuard(aGuard
, aRv
);
119 virtual JSObject
* WrapObject(JSContext
* aCx
,
120 JS::Handle
<JSObject
*> aGivenProto
) override
;
121 nsISupports
* GetParentObject() const { return mOwner
; }
126 InternalHeaders
* GetInternalHeaders() const { return mInternalHeaders
; }
130 } // namespace mozilla
132 #endif // mozilla_dom_Headers_h