Bug 1700051: part 26) Correct typo in comment of `mozInlineSpellWordUtil::BuildSoftTe...
[gecko.git] / dom / fetch / FetchUtil.h
blob5907e209a4f77724605486d5956f231c25dbaef5
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
10 #include "nsString.h"
11 #include "nsError.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"
19 class nsIPrincipal;
20 class nsIHttpChannel;
22 namespace mozilla {
23 namespace dom {
25 class Document;
26 class InternalRequest;
27 class WorkerPrivate;
29 class FetchUtil final {
30 private:
31 FetchUtil() = delete;
33 public:
34 /**
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);
43 /**
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);
55 /**
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);
66 /**
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);
75 } // namespace dom
76 } // namespace mozilla
77 #endif