npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

xypriss-vary

v1.1.3-xypriss

Published

Manipulate the HTTP Vary header - Customized for XyPriss

Downloads

489

Readme

XyPriss Vary Manipulation — xypriss-vary

[!NOTE] Internalized Fork: This module is a strictly typed TypeScript port of the original vary library. It has been internalized into the XyPriss ecosystem to reduce external dependency surfaces and ensure architectural consistency within XyPriss framework plugins.


Overview

xypriss-vary provides utilities to safely build and manipulate the HTTP Vary response header. It handles deduplication, wildcard semantics, and RFC 7230 field-name validation so your middleware never produces a malformed Vary value.


Installation

xfpm install xypriss-vary

Usage

Basic — mark a response as varying on one field

import http from "http";
import vary from "xypriss-vary";

http
  .createServer((req, res) => {
    vary(res, "Accept-Encoding");

    res.statusCode = 200;
    res.setHeader("Content-Type", "text/plain");
    res.end("Operational");
  })
  .listen(3000);

Multiple fields at once

vary(res, ["Accept", "User-Agent", "Origin"]);
// Vary: Accept, User-Agent, Origin

Calling vary multiple times (duplicates are skipped)

Multiple calls on the same res are safe. Fields already present in the header (case-insensitive) are silently ignored.

vary(res, "Accept");
vary(res, "Accept"); // no-op — already present
vary(res, "accept"); // no-op — case-insensitive match
// Vary: Accept

Wildcard

vary(res, "*");
// Vary: *   (signals the response is uncacheable)

Once * is set, any further vary() calls on the same response are no-ops.


Low-level append

Use append when you need to manipulate the header value as a plain string, without touching a ServerResponse directly (useful in unit tests, proxies, or string-based header pipelines).

import { append } from "xypriss-vary";

append("Accept, User-Agent", "Origin");
// → "Accept, User-Agent, Origin"

append("Accept", ["Accept", "Cookie"]);
// → "Accept, Cookie"   (Accept already present — skipped)

append("Accept", "*");
// → "*"

append("*", "Origin");
// → "*"   (wildcard already set — unchanged)

API

vary(res, field)

| Parameter | Type | Description | | --------- | -------------------- | -------------------------------------------------------------------------- | | res | ServerResponse | The active HTTP response to mutate. | | field | string \| string[] | A single field name, a comma-separated string, or an array of field names. |

Returns void.

Throws

  • TypeError — if res is falsy or does not expose getHeader/setHeader.
  • TypeError — if field is falsy or an empty array.
  • TypeError — if any field name is invalid per RFC 7230 §3.2 (with the offending name included in the message).

append(header, field) (named export)

| Parameter | Type | Description | | --------- | -------------------- | ----------------------------------------------------- | | header | string | Current Vary header value (may be an empty string). | | field | string \| string[] | Field name(s) to append. |

Returns string — the updated header value.

Throws

  • TypeError — if header is not a string.
  • TypeError — if field is falsy or an empty array.
  • TypeError — if any field name is invalid per RFC 7230 §3.2.

Error Handling

All validation happens before any mutation, so a TypeError on an invalid field name leaves the response header untouched.

try {
  vary(res, "invalid header!"); // space and ! are not allowed
} catch (e) {
  // TypeError: field argument contains an invalid header name: "invalid header!"
  // res Vary header is unchanged
}

Technical Implementation

  • Strict TypeScript port — no runtime dependencies; full compile-time safety.
  • Pure append function — decoupled from ServerResponse, independently testable.
  • Single-pass parser — the internal parse() function scans the header string once using character codes, with no regex and no intermediate allocations.
  • Validation before mutation — all field names are validated upfront; a bad name aborts the entire call without partial side effects.
  • RFC 7230 §3.2 compliant — field-name validation enforces the token character set exactly.

Changelog

See HISTORY.md for a detailed list of changes and security fixes.