summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/globals.ts2
-rw-r--r--cli/js/tests/headers_test.ts19
-rw-r--r--cli/js/web/body.ts3
-rw-r--r--cli/js/web/dom_types.d.ts22
-rw-r--r--cli/js/web/fetch.ts9
-rw-r--r--cli/js/web/headers.ts7
-rw-r--r--cli/js/web/request.ts6
7 files changed, 22 insertions, 46 deletions
diff --git a/cli/js/globals.ts b/cli/js/globals.ts
index 5a5f54ee1..df9724e63 100644
--- a/cli/js/globals.ts
+++ b/cli/js/globals.ts
@@ -215,7 +215,7 @@ export const windowOrWorkerGlobalScopeProperties = {
EventTarget: nonEnumerable(eventTarget.EventTargetImpl),
URL: nonEnumerable(url.URLImpl),
URLSearchParams: nonEnumerable(urlSearchParams.URLSearchParamsImpl),
- Headers: nonEnumerable(headers.Headers),
+ Headers: nonEnumerable(headers.HeadersImpl),
FormData: nonEnumerable(formData.FormData),
TextEncoder: nonEnumerable(textEncoding.TextEncoder),
TextDecoder: nonEnumerable(textEncoding.TextDecoder),
diff --git a/cli/js/tests/headers_test.ts b/cli/js/tests/headers_test.ts
index 1ed58c9a4..dbc54dc9f 100644
--- a/cli/js/tests/headers_test.ts
+++ b/cli/js/tests/headers_test.ts
@@ -1,5 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { unitTest, assert, assertEquals } from "./test_util.ts";
+import {
+ unitTest,
+ assert,
+ assertEquals,
+ assertStrContains,
+} from "./test_util.ts";
const {
stringifyArgs,
// @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol
@@ -276,9 +281,9 @@ unitTest(function headerParamsArgumentsCheck(): void {
}
}
assertEquals(hasThrown, 2);
- assertEquals(
+ assertStrContains(
errMsg,
- `Headers.${method} requires at least 1 argument, but only 0 present`
+ `${method} requires at least 1 argument, but only 0 present`
);
});
@@ -300,9 +305,9 @@ unitTest(function headerParamsArgumentsCheck(): void {
}
}
assertEquals(hasThrown, 2);
- assertEquals(
+ assertStrContains(
errMsg,
- `Headers.${method} requires at least 2 arguments, but only 0 present`
+ `${method} requires at least 2 arguments, but only 0 present`
);
hasThrown = 0;
@@ -320,9 +325,9 @@ unitTest(function headerParamsArgumentsCheck(): void {
}
}
assertEquals(hasThrown, 2);
- assertEquals(
+ assertStrContains(
errMsg,
- `Headers.${method} requires at least 2 arguments, but only 1 present`
+ `${method} requires at least 2 arguments, but only 1 present`
);
});
});
diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts
index 472f3fda2..f4fc4a3e2 100644
--- a/cli/js/web/body.ts
+++ b/cli/js/web/body.ts
@@ -1,12 +1,9 @@
import * as formData from "./form_data.ts";
import * as blob from "./blob.ts";
import * as encoding from "./text_encoding.ts";
-import * as headers from "./headers.ts";
import * as domTypes from "./dom_types.d.ts";
import { ReadableStream } from "./streams/mod.ts";
-const { Headers } = headers;
-
// only namespace imports work for now, plucking out what we need
const { FormData } = formData;
const { TextEncoder, TextDecoder } = encoding;
diff --git a/cli/js/web/dom_types.d.ts b/cli/js/web/dom_types.d.ts
index 5ec6e8b1a..dfd4a8460 100644
--- a/cli/js/web/dom_types.d.ts
+++ b/cli/js/web/dom_types.d.ts
@@ -17,11 +17,6 @@ and limitations under the License.
/* eslint-disable @typescript-eslint/no-explicit-any */
-export type HeadersInit =
- | Headers
- | Array<[string, string]>
- | Record<string, string>;
-
type BodyInit =
| Blob
| BufferSource
@@ -513,23 +508,6 @@ export interface QueuingStrategySizeCallback<T = any> {
(chunk: T): number;
}
-export class Headers {
- constructor(init?: HeadersInit);
- append(name: string, value: string): void;
- delete(name: string): void;
- get(name: string): string | null;
- has(name: string): boolean;
- set(name: string, value: string): void;
- forEach(
- callbackfn: (value: string, key: string, parent: this) => void,
- thisArg?: any
- ): void;
- [Symbol.iterator](): IterableIterator<[string, string]>;
- entries(): IterableIterator<[string, string]>;
- keys(): IterableIterator<string>;
- values(): IterableIterator<string>;
-}
-
type RequestCache =
| "default"
| "no-store"
diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts
index 5a5ac5cfe..10ce821c1 100644
--- a/cli/js/web/fetch.ts
+++ b/cli/js/web/fetch.ts
@@ -4,7 +4,6 @@ import { isTypedArray } from "./util.ts";
import * as domTypes from "./dom_types.d.ts";
import { TextDecoder, TextEncoder } from "./text_encoding.ts";
import { DenoBlob, bytesSymbol as blobBytesSymbol } from "./blob.ts";
-import { Headers } from "./headers.ts";
import * as io from "../io.ts";
import { read } from "../ops/io.ts";
import { close } from "../ops/resources.ts";
@@ -277,8 +276,8 @@ class Body
export class Response implements domTypes.Response {
readonly type: domTypes.ResponseType;
readonly redirected: boolean;
- headers: domTypes.Headers;
- readonly trailer: Promise<domTypes.Headers>;
+ headers: Headers;
+ readonly trailer: Promise<Headers>;
readonly body: Body | null;
constructor(
@@ -467,7 +466,7 @@ export class Response implements domTypes.Response {
function sendFetchReq(
url: string,
method: string | null,
- headers: domTypes.Headers | null,
+ headers: Headers | null,
body: ArrayBufferView | undefined
): Promise<FetchResponse> {
let headerArray: Array<[string, string]> = [];
@@ -490,7 +489,7 @@ export async function fetch(
): Promise<Response> {
let url: string;
let method: string | null = null;
- let headers: domTypes.Headers | null = null;
+ let headers: Headers | null = null;
let body: ArrayBufferView | undefined;
let redirected = false;
let remRedirectCount = 20; // TODO: use a better way to handle
diff --git a/cli/js/web/headers.ts b/cli/js/web/headers.ts
index 1f750faa3..fe42a81c9 100644
--- a/cli/js/web/headers.ts
+++ b/cli/js/web/headers.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types.d.ts";
import { DomIterableMixin } from "./dom_iterable.ts";
import { requiredArguments } from "./util.ts";
import { customInspect } from "./console.ts";
@@ -10,7 +9,7 @@ const invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
-function isHeaders(value: any): value is domTypes.Headers {
+function isHeaders(value: any): value is Headers {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return value instanceof Headers;
}
@@ -44,7 +43,7 @@ function validateValue(value: string): void {
class HeadersBase {
[headerMap]: Map<string, string>;
- constructor(init?: domTypes.HeadersInit) {
+ constructor(init?: HeadersInit) {
if (init === null) {
throw new TypeError(
"Failed to construct 'Headers'; The provided value was not valid"
@@ -145,7 +144,7 @@ class HeadersBase {
}
// @internal
-export class Headers extends DomIterableMixin<
+export class HeadersImpl extends DomIterableMixin<
string,
string,
typeof HeadersBase
diff --git a/cli/js/web/request.ts b/cli/js/web/request.ts
index 6a5d92a2b..75f66b7cc 100644
--- a/cli/js/web/request.ts
+++ b/cli/js/web/request.ts
@@ -1,10 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import * as headers from "./headers.ts";
import * as body from "./body.ts";
import * as domTypes from "./dom_types.d.ts";
import * as streams from "./streams/mod.ts";
-const { Headers } = headers;
const { ReadableStream } = streams;
function byteUpperCase(s: string): string {
@@ -32,7 +30,7 @@ export class Request extends body.Body implements domTypes.Request {
public method: string;
public url: string;
public credentials?: "omit" | "same-origin" | "include";
- public headers: domTypes.Headers;
+ public headers: Headers;
constructor(input: domTypes.RequestInfo, init?: domTypes.RequestInit) {
if (arguments.length < 1) {
@@ -62,7 +60,7 @@ export class Request extends body.Body implements domTypes.Request {
b = "";
}
- let headers: domTypes.Headers;
+ let headers: Headers;
// prefer headers from init
if (init.headers) {