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 🙏

© 2025 – Pkg Stats / Ryan Hefner

x-middleware-util

v1.0.1

Published

[Build Status](https://travis-ci.org/x-component/x-middleware-util.png?v1.0.0)](https://travis-ci.org/x-component/x-middleware-util)

Downloads

4

Readme

x-middleware-util

Build Status](https://travis-ci.org/x-component/x-middleware-util)

./condition.js

./end.js

./error.js

./index.js

./mode.js

bool

Test middleware, checks if differents modes are active e.g. header X-x-template

./redirect.js

./util.js

url

adds some utility functions to respons and request

undefined.vary()

get a header and add the name to response Vary headers, as the requested header will determine the response content.

Note: besides the header value often also its absence will determine the response content. Therefore the header still should occur in the Vary headers. Only a correct response Vary header allows a correct web caching.

undefined.type()

mix between accept and url matching to check for a specfic request type because accept is offten to wide in accepting results therefore express accept is no good enough p.e. a chrome request will lead to accept image also if it accepts html. While correct the sematics is problematic.

undefined.rewrite()

rewrite the current url to the a new url, adapts also req.query optionally passes previous req.query {query:true}

undefined.addHeader()

add an header value, if a value already exists then add this value to an array of values as node allows multiple header values within an array Note: this is case sensitive, as we can send in node with a specific upper/lower case name. Only values with same case in the name are merged into an array This is done for compatibility. Case should be ignored in HTTP, but some clients and other server don't ignore it. Thereby we should SEND in the common upper/lower case format: Set-Cooke, Content-Type etc.

setHeader

we wrap setHeader to check if some one tries to to set the heder after the response is al ready send this is a common mistake if a pipeline already has ended or there is some where a double next call. The first one sends the repsonse body The wrong second call tries to set headers and/or send again a body Note: the Etag setting of express connect sometimes produces this error

undefined.getHeaders()

get all headers set with their case sensitive names as they where set in node we can receive headers just in lower case, but send them in the case we define

writeHead

wrap writeHead to convert the vary header to a single string if it is an array, as Varnish requires this format and set a header x-o2-set-cookies to inform varnish about all cookie names we set this way varnish doesn't need to parse the single set cookie headers

undefined.setHeaderFilter(name:, filter(name,value):)

this allows the to define a function which is called whenever a setHeader is called. On can therfore change/prevent certain header settings if perfromed by (external) middlewares lateron in the pipeline