1.0.0-beta.1 • Published 1 year ago

@httpland/hsts-parser v1.0.0-beta.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

hsts-parser

deno land deno doc GitHub release (latest by date) codecov GitHub

test NPM

HTTP Strict Transport Security(HSTS) header field parser.

Compliant with RFC 6797, 6.1. Strict-Transport-Security HTTP Response Header Field.

Strict Transport Security

StrictTransportSecurity is a structured object of Strict-Transport-Security header .

NameTypeRequiredDescription
maxAgenumber:white_check_mark:The number of seconds, after the reception of the STS header field, during which the UA regards the host.
includeSubDomainsboolean-Whether the rule applies to all subdomains or not.
preloadboolean-Whether the domain do preload or not.

Serialization

Serializes Strict Transport Security into string.

import { stringify } from "https://deno.land/x/hsts_parser@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(
  stringify({
    maxAge: 60 * 60 * 24 * 180,
    includeSubDomains: true,
    preload: true,
  }),
  "max-age=15552000; includeSubDomains; preload",
);

Throwing error

Throws TypeError if Strict Transport Security contains errors.

import { stringify } from "https://deno.land/x/hsts_parser@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";

assertThrows(() => stringify({ maxAge: NaN }));

License

Copyright © 2023-present httpland.

Released under the MIT license