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_Response_h
8 #define mozilla_dom_Response_h
10 #include "nsWrapperCache.h"
11 #include "nsISupportsImpl.h"
13 #include "mozilla/dom/Fetch.h"
14 #include "mozilla/dom/ResponseBinding.h"
16 #include "InternalHeaders.h"
17 #include "InternalResponse.h"
28 class Response final
: public FetchBody
<Response
>, public nsWrapperCache
{
29 NS_DECL_ISUPPORTS_INHERITED
30 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Response
,
34 Response(nsIGlobalObject
* aGlobal
, InternalResponse
* aInternalResponse
,
35 AbortSignalImpl
* aSignalImpl
);
37 Response(const Response
& aOther
) = delete;
39 JSObject
* WrapObject(JSContext
* aCx
,
40 JS::Handle
<JSObject
*> aGivenProto
) override
{
41 return Response_Binding::Wrap(aCx
, this, aGivenProto
);
44 ResponseType
Type() const { return mInternalResponse
->Type(); }
45 void GetUrl(nsAString
& aUrl
) const {
46 CopyUTF8toUTF16(mInternalResponse
->GetURL(), aUrl
);
48 bool Redirected() const { return mInternalResponse
->IsRedirected(); }
49 uint16_t Status() const { return mInternalResponse
->GetStatus(); }
52 return mInternalResponse
->GetStatus() >= 200 &&
53 mInternalResponse
->GetStatus() <= 299;
56 void GetStatusText(nsCString
& aStatusText
) const {
57 aStatusText
= mInternalResponse
->GetStatusText();
60 InternalHeaders
* GetInternalHeaders() const {
61 return mInternalResponse
->Headers();
64 void InitChannelInfo(nsIChannel
* aChannel
) {
65 mInternalResponse
->InitChannelInfo(aChannel
);
68 const ChannelInfo
& GetChannelInfo() const {
69 return mInternalResponse
->GetChannelInfo();
72 const UniquePtr
<mozilla::ipc::PrincipalInfo
>& GetPrincipalInfo() const {
73 return mInternalResponse
->GetPrincipalInfo();
76 bool HasCacheInfoChannel() const {
77 return mInternalResponse
->HasCacheInfoChannel();
82 void GetBody(nsIInputStream
** aStream
, int64_t* aBodyLength
= nullptr) {
83 mInternalResponse
->GetBody(aStream
, aBodyLength
);
86 using FetchBody::GetBody
;
88 using FetchBody::BodyBlobURISpec
;
90 const nsACString
& BodyBlobURISpec() const {
91 return mInternalResponse
->BodyBlobURISpec();
94 using FetchBody::BodyLocalPath
;
96 const nsAString
& BodyLocalPath() const {
97 return mInternalResponse
->BodyLocalPath();
100 static already_AddRefed
<Response
> Error(const GlobalObject
& aGlobal
);
102 static already_AddRefed
<Response
> Redirect(const GlobalObject
& aGlobal
,
103 const nsAString
& aUrl
,
107 static already_AddRefed
<Response
> Constructor(
108 const GlobalObject
& aGlobal
,
109 const Nullable
<fetch::ResponseBodyInit
>& aBody
, const ResponseInit
& aInit
,
112 nsIGlobalObject
* GetParentObject() const { return mOwner
; }
114 already_AddRefed
<Response
> Clone(JSContext
* aCx
, ErrorResult
& aRv
);
116 already_AddRefed
<Response
> CloneUnfiltered(JSContext
* aCx
, ErrorResult
& aRv
);
118 void SetBody(nsIInputStream
* aBody
, int64_t aBodySize
);
120 already_AddRefed
<InternalResponse
> GetInternalResponse() const;
122 AbortSignalImpl
* GetSignalImpl() const override
{ return mSignalImpl
; }
127 RefPtr
<InternalResponse
> mInternalResponse
;
129 RefPtr
<Headers
> mHeaders
;
130 RefPtr
<AbortSignalImpl
> mSignalImpl
;
134 } // namespace mozilla
136 #endif // mozilla_dom_Response_h