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_FetchUtil_h
8 #define mozilla_dom_FetchUtil_h
13 #include "mozilla/dom/File.h"
14 #include "mozilla/dom/FormData.h"
16 #define WASM_CONTENT_TYPE "application/wasm"
17 #define WASM_ALT_DATA_TYPE_V1 "wasm/machine-code/1"
26 class InternalRequest
;
29 class FetchUtil final
{
35 * Sets outMethod to a valid HTTP request method string based on an input
36 * method. Implements checks and normalization as specified by the Fetch
37 * specification. Returns NS_ERROR_DOM_SECURITY_ERR if the method is invalid.
38 * Otherwise returns NS_OK and the normalized method via outMethod.
40 static nsresult
GetValidRequestMethod(const nsACString
& aMethod
,
41 nsCString
& outMethod
);
44 * Extracts an HTTP header from a substring range.
46 static bool ExtractHeader(nsACString::const_iterator
& aStart
,
47 nsACString::const_iterator
& aEnd
,
48 nsCString
& aHeaderName
, nsCString
& aHeaderValue
,
49 bool* aWasEmptyHeader
);
51 static nsresult
SetRequestReferrer(nsIPrincipal
* aPrincipal
, Document
* aDoc
,
52 nsIHttpChannel
* aChannel
,
53 InternalRequest
& aRequest
);
56 * Check that the given object is a Response and, if so, stream to the given
57 * JS consumer. On any failure, this function will report an error on the
58 * given JSContext before returning false. If executing in a worker, the
59 * WorkerPrivate must be given.
61 static bool StreamResponseToJS(JSContext
* aCx
, JS::HandleObject aObj
,
62 JS::MimeType aMimeType
,
63 JS::StreamConsumer
* aConsumer
,
64 WorkerPrivate
* aMaybeWorker
);
67 * Called by JS to report (i.e., throw) an error that was passed to the
68 * JS::StreamConsumer::streamError() method on a random stream thread.
69 * This method is passed by function pointer to the JS engine hence the
70 * untyped 'size_t' instead of Gecko 'nsresult'.
72 static void ReportJSStreamError(JSContext
* aCx
, size_t aErrorCode
);
76 } // namespace mozilla