Bug 1449132 [wpt PR 10194] - [css-grid] Fix resolution of percentage paddings and...
[gecko.git] / dom / fetch / FetchUtil.h
blob9e3c44a61c77f11b1423182db5cbc12122533bd3
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/ErrorResult.h"
14 #include "mozilla/dom/File.h"
15 #include "mozilla/dom/FormData.h"
17 class nsIPrincipal;
18 class nsIDocument;
19 class nsIHttpChannel;
21 namespace mozilla {
22 namespace dom {
24 class InternalRequest;
25 class WorkerPrivate;
27 class FetchUtil final
29 private:
30 FetchUtil() = delete;
32 public:
33 /**
34 * Sets outMethod to a valid HTTP request method string based on an input method.
35 * Implements checks and normalization as specified by the Fetch specification.
36 * Returns NS_ERROR_DOM_SECURITY_ERR if the method is invalid.
37 * Otherwise returns NS_OK and the normalized method via outMethod.
39 static nsresult
40 GetValidRequestMethod(const nsACString& aMethod, nsCString& outMethod);
42 /**
43 * Extracts an HTTP header from a substring range.
45 static bool
46 ExtractHeader(nsACString::const_iterator& aStart,
47 nsACString::const_iterator& aEnd,
48 nsCString& aHeaderName,
49 nsCString& aHeaderValue,
50 bool* aWasEmptyHeader);
52 static nsresult
53 SetRequestReferrer(nsIPrincipal* aPrincipal,
54 nsIDocument* aDoc,
55 nsIHttpChannel* aChannel,
56 InternalRequest* aRequest);
58 /**
59 * Check that the given object is a Response and, if so, stream to the given
60 * JS consumer. On any failure, this function will report an error on the
61 * given JSContext before returning false. If executing in a worker, the
62 * WorkerPrivate must be given.
64 static bool
65 StreamResponseToJS(JSContext* aCx,
66 JS::HandleObject aObj,
67 JS::MimeType aMimeType,
68 JS::StreamConsumer* aConsumer,
69 WorkerPrivate* aMaybeWorker);
72 } // namespace dom
73 } // namespace mozilla
74 #endif