summaryrefslogtreecommitdiff
path: root/js/fetch.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-11-02 21:43:37 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-11-02 20:50:01 -0700
commit6446bc532840319ac9603c016e2ef419094fdeec (patch)
tree401e4a70956602dbbb032d942226c64ae2fbb5c4 /js/fetch.ts
parentee24254bade280ea3c0121c074951396863393ac (diff)
Move fetch headers into its own file.
Diffstat (limited to 'js/fetch.ts')
-rw-r--r--js/fetch.ts84
1 files changed, 1 insertions, 83 deletions
diff --git a/js/fetch.ts b/js/fetch.ts
index f4c7aaf81..16172b776 100644
--- a/js/fetch.ts
+++ b/js/fetch.ts
@@ -13,89 +13,7 @@ import * as msg from "gen/msg_generated";
import * as domTypes from "./dom_types";
import { TextDecoder } from "./text_encoding";
import { DenoBlob } from "./blob";
-import { DomIterableMixin } from "./mixins/dom_iterable";
-
-// tslint:disable-next-line:no-any
-function isHeaders(value: any): value is domTypes.Headers {
- return value instanceof Headers;
-}
-
-const headerMap = Symbol("header map");
-
-// ref: https://fetch.spec.whatwg.org/#dom-headers
-class HeadersBase {
- private [headerMap]: Map<string, string>;
-
- private _normalizeParams(name: string, value?: string): string[] {
- name = String(name).toLowerCase();
- value = String(value).trim();
- return [name, value];
- }
-
- constructor(init?: domTypes.HeadersInit) {
- if (init === null) {
- throw new TypeError(
- "Failed to construct 'Headers'; The provided value was not valid"
- );
- } else if (isHeaders(init)) {
- this[headerMap] = new Map(init);
- } else {
- this[headerMap] = new Map();
- if (Array.isArray(init)) {
- for (const [rawName, rawValue] of init) {
- const [name, value] = this._normalizeParams(rawName, rawValue);
- const existingValue = this[headerMap].get(name);
- this[headerMap].set(
- name,
- existingValue ? `${existingValue}, ${value}` : value
- );
- }
- } else if (init) {
- const names = Object.keys(init);
- for (const rawName of names) {
- const rawValue = init[rawName];
- const [name, value] = this._normalizeParams(rawName, rawValue);
- this[headerMap].set(name, value);
- }
- }
- }
- }
-
- append(name: string, value: string): void {
- const [newname, newvalue] = this._normalizeParams(name, value);
- const v = this[headerMap].get(newname);
- const str = v ? `${v}, ${newvalue}` : newvalue;
- this[headerMap].set(newname, str);
- }
-
- delete(name: string): void {
- const [newname] = this._normalizeParams(name);
- this[headerMap].delete(newname);
- }
-
- get(name: string): string | null {
- const [newname] = this._normalizeParams(name);
- const value = this[headerMap].get(newname);
- return value || null;
- }
-
- has(name: string): boolean {
- const [newname] = this._normalizeParams(name);
- return this[headerMap].has(newname);
- }
-
- set(name: string, value: string): void {
- const [newname, newvalue] = this._normalizeParams(name, value);
- this[headerMap].set(newname, newvalue);
- }
-}
-
-// @internal
-// tslint:disable-next-line:variable-name
-export const Headers = DomIterableMixin<string, string, typeof HeadersBase>(
- HeadersBase,
- headerMap
-);
+import { Headers } from "./headers";
class FetchResponse implements domTypes.Response {
readonly url: string = "";