Giter VIP home page Giter VIP logo

hapi-etags's Introduction

hapi-etags


hapi will automatically generate ETag headers for your responses when you use the file handler or reply.file() method. But if you're using any other kind of response (such as JSON, HTML, text etc) you won't get ETags for free. This plugin fixes that!

##Installation and configuration

To install, just add to your npm deps:

npm install --save hapi-etags

Then register the plugin:

server.register([
    {
        register: require('hapi-etags'),
        options: {
			// explained below
        }
    }
], function (err) {

    if (err) {
        throw err;
    }

    server.start(function () {
        console.log('Started!');
    });

});

The following options are available when registering the plugin [defaults]:

  • algo - The hashing function to use to calculate the ETag. Can be anything in Crypto.getHashes() Default: sha1
  • encoding - The encoding to use for the ETag hash. Can be base64 or hex. Default: 'base64'
  • varieties - A list of the variety types that the plugin will calculate etags for. Options are ['plain', 'buffer', 'view', 'stream']. Default: ['plain', 'buffer']
  • etagOptions - The same options argument that's passed to response.etag (http://hapijs.com/api#response-object-redirect-methods). Default: {}

##Advice and warnings

Only the plain and buffer varieties are set by default. Support for the other varieties should be considered experimental. Here's some issues to be aware of:

  • view - Has to pre-render the view template to calculate the ETag so a performance hit will be taken.
  • stream - Has to read and buffer the entire stream data into memory to calculate the ETag. Clients could be waiting while this happens. Could totally break the responsiveness of your app - beware! Only makes sense to use this when your clients have bandwidth limitations and you're willing to go to extreme lengths to prevent them redownloading streamed content.

hapi-etags's People

Contributors

mtharrison avatar

Watchers

James Cloos avatar Maxim Baev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.