Bug 1848468 - Mark k-rate-dynamics-compressor-connections.html subtest as failing...
[gecko.git] / dom / fetch / FetchUtil.h
blobc0c9157a43c867a306ce6c4401d378d3f854d55c
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"
18 class nsIPrincipal;
19 class nsIHttpChannel;
21 namespace mozilla::dom {
23 class Document;
24 class InternalRequest;
25 class WorkerPrivate;
27 class FetchUtil final {
28 private:
29 FetchUtil() = delete;
31 public:
32 /**
33 * Sets outMethod to a valid HTTP request method string based on an input
34 * method. Implements checks and normalization as specified by the Fetch
35 * specification. Returns NS_ERROR_DOM_SECURITY_ERR if the method is invalid.
36 * Otherwise returns NS_OK and the normalized method via outMethod.
38 static nsresult GetValidRequestMethod(const nsACString& aMethod,
39 nsCString& outMethod);
40 /**
41 * Extracts an HTTP header from a substring range.
43 static bool ExtractHeader(nsACString::const_iterator& aStart,
44 nsACString::const_iterator& aEnd,
45 nsCString& aHeaderName, nsCString& aHeaderValue,
46 bool* aWasEmptyHeader);
48 static nsresult SetRequestReferrer(nsIPrincipal* aPrincipal, Document* aDoc,
49 nsIHttpChannel* aChannel,
50 InternalRequest& aRequest);
52 /**
53 * The WebAssembly alt data type includes build-id, cpu-id and other relevant
54 * state that is necessary to ensure the validity of caching machine code and
55 * metadata in alt data. InitWasmAltDataType() must be called during startup
56 * before the first fetch(), ensuring that !WasmAltDataType.IsEmpty().
58 static const nsCString WasmAltDataType;
59 static void InitWasmAltDataType();
61 /**
62 * Check that the given object is a Response and, if so, stream to the given
63 * JS consumer. On any failure, this function will report an error on the
64 * given JSContext before returning false. If executing in a worker, the
65 * WorkerPrivate must be given.
67 static bool StreamResponseToJS(JSContext* aCx, JS::Handle<JSObject*> aObj,
68 JS::MimeType aMimeType,
69 JS::StreamConsumer* aConsumer,
70 WorkerPrivate* aMaybeWorker);
72 /**
73 * Called by JS to report (i.e., throw) an error that was passed to the
74 * JS::StreamConsumer::streamError() method on a random stream thread.
75 * This method is passed by function pointer to the JS engine hence the
76 * untyped 'size_t' instead of Gecko 'nsresult'.
78 static void ReportJSStreamError(JSContext* aCx, size_t aErrorCode);
81 } // namespace mozilla::dom
82 #endif