Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

dmpjs/vary

Repository files navigation

vary

Manipulate the HTTP Vary header.

Vary is based on vary and has been ported for use on Deno

Installation

Use the following import:

import { vary } from "https://raw.githubusercontent.com/dmpjs/vary/master/mod.ts"; // import from github as raw data

import { vary } from "https://deno.land/x/vary/mod.ts"; // If module is uploaded into deno.land

Usage

Vary(responseHeadersGet, responseHeadersSet, field)

Adds the given header field to the Vary response header of response. This can be a string of a single field, a string of a valid Vary header, or an array of multiple fields.

This will append the header if not already listed, otherwise leaves it listed in the current location.

import { Drash } from "https://deno.land/x/drash@v1.0.5/mod.ts";
import { vary } from "https://raw.githubusercontent.com/dmpjs/vary/master/mod.ts";

let response: Drash.response

// Append "Origin" to the Vary header of the response
vary(
    (header: string) => response.headers.get(header) || "",
    (header: string, value: string) => { response.headers.set(header, value)},
    'Origin'
)

Append(header, field)

Adds the given header field to the Vary response header string header. This can be a string of a single field, a string of a valid Vary header, or an array of multiple fields.

This will append the header if not already listed, otherwise leaves it listed in the current location. The new header string is returned.

import { append } from "https://raw.githubusercontent.com/dmpjs/vary/master/mod.ts";

// Get header string appending "Origin" to "Accept, User-Agent"
append('Accept, User-Agent', 'Origin')

Test

Run

deno test ./test.ts

Versioning

This library follows semantic versioning, and additions to the code ruleset are performed in major releases.

Changelog

Please have a look at CHANGELOG.md.

Contributing

Please have a look at CONTRIBUTING.md.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.