1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_Response_h
7 #define mozilla_dom_Response_h
9 #include "nsWrapperCache.h"
10 #include "nsISupportsImpl.h"
12 #include "mozilla/dom/Fetch.h"
13 #include "mozilla/dom/ResponseBinding.h"
15 #include "InternalResponse.h"
22 class ArrayBufferOrArrayBufferViewOrUSVStringOrURLSearchParams
;
24 class InternalHeaders
;
27 class Response MOZ_FINAL
: public nsISupports
28 , public nsWrapperCache
29 , public FetchBody
<Response
>
31 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
32 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Response
)
35 Response(nsIGlobalObject
* aGlobal
, InternalResponse
* aInternalResponse
);
37 Response(const Response
& aOther
) = delete;
40 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
42 return ResponseBinding::Wrap(aCx
, this);
48 return mInternalResponse
->Type();
52 GetUrl(DOMString
& aUrl
) const
55 mInternalResponse
->GetUrl(url
);
56 aUrl
.AsAString() = NS_ConvertUTF8toUTF16(url
);
62 return mInternalResponse
->GetStatus();
66 GetStatusText(nsCString
& aStatusText
) const
68 aStatusText
= mInternalResponse
->GetStatusText();
72 GetInternalHeaders() const
74 return mInternalResponse
->Headers();
80 GetBody(nsIInputStream
** aStream
) { return mInternalResponse
->GetBody(aStream
); }
82 static already_AddRefed
<Response
>
83 Error(const GlobalObject
& aGlobal
);
85 static already_AddRefed
<Response
>
86 Redirect(const GlobalObject
& aGlobal
, const nsAString
& aUrl
, uint16_t aStatus
);
88 static already_AddRefed
<Response
>
89 Constructor(const GlobalObject
& aGlobal
,
90 const Optional
<ArrayBufferOrArrayBufferViewOrBlobOrUSVStringOrURLSearchParams
>& aBody
,
91 const ResponseInit
& aInit
, ErrorResult
& rv
);
93 nsIGlobalObject
* GetParentObject() const
98 already_AddRefed
<Response
>
102 SetBody(nsIInputStream
* aBody
);
106 nsCOMPtr
<nsIGlobalObject
> mOwner
;
107 nsRefPtr
<InternalResponse
> mInternalResponse
;
109 nsRefPtr
<Headers
> mHeaders
;
113 } // namespace mozilla
115 #endif // mozilla_dom_Response_h