diff options
author | Rory Malcolm <rory.malcolm@digital.cabinet-office.gov.uk> | 2019-10-28 16:23:39 +0000 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-10-28 12:23:39 -0400 |
commit | 967c236fa5fb1e87e1b5ee788fe77d3a07361da1 (patch) | |
tree | 839f348ec0e9a80f41a381dd60b0b61f5cfb33a5 /cli/js/headers.ts | |
parent | efd7e78af3fc086dfdec51738905665d38d08eb4 (diff) |
Add CustomInspect for Headers (#3130)
Worth noting due to implementation of the Headers class the contents of headersMap have lowercase keys, although this matches the specification as header keys are case agnostic it does seem to not match behaviour of other implementations in other languages I have seen, would require some rewriting of Headers.ts
Diffstat (limited to 'cli/js/headers.ts')
-rw-r--r-- | cli/js/headers.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/cli/js/headers.ts b/cli/js/headers.ts index dc0de54dd..cc22077ad 100644 --- a/cli/js/headers.ts +++ b/cli/js/headers.ts @@ -2,6 +2,7 @@ import * as domTypes from "./dom_types.ts"; import { DomIterableMixin } from "./mixins/dom_iterable.ts"; import { requiredArguments } from "./util.ts"; +import { customInspect } from "./console.ts"; // From node-fetch // Copyright (c) 2016 David Frank. MIT License. @@ -85,6 +86,18 @@ class HeadersBase { } } + [customInspect](): string { + let headerSize = this[headerMap].size; + let output = ""; + this[headerMap].forEach((value, key) => { + const prefix = headerSize === this[headerMap].size ? " " : ""; + const postfix = headerSize === 1 ? " " : ", "; + output = output + `${prefix}${key}: ${value}${postfix}`; + headerSize--; + }); + return `Headers {${output}}`; + } + // ref: https://fetch.spec.whatwg.org/#concept-headers-append append(name: string, value: string): void { requiredArguments("Headers.append", arguments.length, 2); |