From d997f92b892040860145a9510504dff22f672a36 Mon Sep 17 00:00:00 2001 From: Nikita Kobzev Date: Thu, 28 Jul 2016 17:28:41 +0300 Subject: [PATCH] Added Headers constructor options to whatwg-fetch (#10313) --- whatwg-fetch/whatwg-fetch-tests.ts | 13 +++++++++++++ whatwg-fetch/whatwg-fetch.d.ts | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/whatwg-fetch/whatwg-fetch-tests.ts b/whatwg-fetch/whatwg-fetch-tests.ts index 8dbbd2964b..090e114b5d 100644 --- a/whatwg-fetch/whatwg-fetch-tests.ts +++ b/whatwg-fetch/whatwg-fetch-tests.ts @@ -1,5 +1,18 @@ /// +function test_HeadersCopiedFromHeaders() { + var source = new Headers(); + source.append('Content-Type', 'application/json'); + return new Headers(source); +} + +function test_HeadersCopiedFromHash() { + var source:HeadersMap = { + 'Content-Type': 'application/json' + }; + return new Headers(source); +} + function test_fetchUrlWithOptions() { var headers = new Headers(); headers.append("Content-Type", "application/json"); diff --git a/whatwg-fetch/whatwg-fetch.d.ts b/whatwg-fetch/whatwg-fetch.d.ts index 8997ab6917..5a428fb47b 100644 --- a/whatwg-fetch/whatwg-fetch.d.ts +++ b/whatwg-fetch/whatwg-fetch.d.ts @@ -41,7 +41,12 @@ type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached"; +declare interface HeadersMap { + [index: string]: string; +} + declare class Headers { + constructor(headers?:Headers|HeadersMap) append(name: string, value: string): void; delete(name: string):void; get(name: string): string; @@ -60,6 +65,7 @@ declare class Body { json(): Promise; text(): Promise; } + declare class Response extends Body { constructor(body?: BodyInit, init?: ResponseInit); static error(): Response;