summaryrefslogtreecommitdiff
path: root/cli/js/web/headers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/web/headers.ts')
-rw-r--r--cli/js/web/headers.ts80
1 files changed, 40 insertions, 40 deletions
diff --git a/cli/js/web/headers.ts b/cli/js/web/headers.ts
index 9ff594224..e1d81393d 100644
--- a/cli/js/web/headers.ts
+++ b/cli/js/web/headers.ts
@@ -17,32 +17,32 @@ function isHeaders(value: any): value is domTypes.Headers {
const headerMap = Symbol("header map");
-// ref: https://fetch.spec.whatwg.org/#dom-headers
-class HeadersBase {
- private [headerMap]: Map<string, string>;
- // TODO: headerGuard? Investigate if it is needed
- // node-fetch did not implement this but it is in the spec
-
- private _normalizeParams(name: string, value?: string): string[] {
- name = String(name).toLowerCase();
- value = String(value).trim();
- return [name, value];
- }
+// TODO: headerGuard? Investigate if it is needed
+// node-fetch did not implement this but it is in the spec
+function normalizeParams(name: string, value?: string): string[] {
+ name = String(name).toLowerCase();
+ value = String(value).trim();
+ return [name, value];
+}
- // The following name/value validations are copied from
- // https://github.com/bitinn/node-fetch/blob/master/src/headers.js
- // Copyright (c) 2016 David Frank. MIT License.
- private _validateName(name: string): void {
- if (invalidTokenRegex.test(name) || name === "") {
- throw new TypeError(`${name} is not a legal HTTP header name`);
- }
+// The following name/value validations are copied from
+// https://github.com/bitinn/node-fetch/blob/master/src/headers.js
+// Copyright (c) 2016 David Frank. MIT License.
+function validateName(name: string): void {
+ if (invalidTokenRegex.test(name) || name === "") {
+ throw new TypeError(`${name} is not a legal HTTP header name`);
}
+}
- private _validateValue(value: string): void {
- if (invalidHeaderCharRegex.test(value)) {
- throw new TypeError(`${value} is not a legal HTTP header value`);
- }
+function validateValue(value: string): void {
+ if (invalidHeaderCharRegex.test(value)) {
+ throw new TypeError(`${value} is not a legal HTTP header value`);
}
+}
+
+// ref: https://fetch.spec.whatwg.org/#dom-headers
+class HeadersBase {
+ [headerMap]: Map<string, string>;
constructor(init?: domTypes.HeadersInit) {
if (init === null) {
@@ -64,9 +64,9 @@ class HeadersBase {
2
);
- const [name, value] = this._normalizeParams(tuple[0], tuple[1]);
- this._validateName(name);
- this._validateValue(value);
+ const [name, value] = normalizeParams(tuple[0], tuple[1]);
+ validateName(name);
+ validateValue(value);
const existingValue = this[headerMap].get(name);
this[headerMap].set(
name,
@@ -77,9 +77,9 @@ class HeadersBase {
const names = Object.keys(init);
for (const rawName of names) {
const rawValue = init[rawName];
- const [name, value] = this._normalizeParams(rawName, rawValue);
- this._validateName(name);
- this._validateValue(value);
+ const [name, value] = normalizeParams(rawName, rawValue);
+ validateName(name);
+ validateValue(value);
this[headerMap].set(name, value);
}
}
@@ -101,9 +101,9 @@ class HeadersBase {
// ref: https://fetch.spec.whatwg.org/#concept-headers-append
append(name: string, value: string): void {
requiredArguments("Headers.append", arguments.length, 2);
- const [newname, newvalue] = this._normalizeParams(name, value);
- this._validateName(newname);
- this._validateValue(newvalue);
+ const [newname, newvalue] = normalizeParams(name, value);
+ validateName(newname);
+ validateValue(newvalue);
const v = this[headerMap].get(newname);
const str = v ? `${v}, ${newvalue}` : newvalue;
this[headerMap].set(newname, str);
@@ -111,31 +111,31 @@ class HeadersBase {
delete(name: string): void {
requiredArguments("Headers.delete", arguments.length, 1);
- const [newname] = this._normalizeParams(name);
- this._validateName(newname);
+ const [newname] = normalizeParams(name);
+ validateName(newname);
this[headerMap].delete(newname);
}
get(name: string): string | null {
requiredArguments("Headers.get", arguments.length, 1);
- const [newname] = this._normalizeParams(name);
- this._validateName(newname);
+ const [newname] = normalizeParams(name);
+ validateName(newname);
const value = this[headerMap].get(newname);
return value || null;
}
has(name: string): boolean {
requiredArguments("Headers.has", arguments.length, 1);
- const [newname] = this._normalizeParams(name);
- this._validateName(newname);
+ const [newname] = normalizeParams(name);
+ validateName(newname);
return this[headerMap].has(newname);
}
set(name: string, value: string): void {
requiredArguments("Headers.set", arguments.length, 2);
- const [newname, newvalue] = this._normalizeParams(name, value);
- this._validateName(newname);
- this._validateValue(newvalue);
+ const [newname, newvalue] = normalizeParams(name, value);
+ validateName(newname);
+ validateValue(newvalue);
this[headerMap].set(newname, newvalue);
}