Skip to content

Instantly share code, notes, and snippets.

@trezy
Last active October 19, 2017 14:40
Show Gist options
  • Select an option

  • Save trezy/86d22bfc3c7bc066b0e108e7796c8c15 to your computer and use it in GitHub Desktop.

Select an option

Save trezy/86d22bfc3c7bc066b0e108e7796c8c15 to your computer and use it in GitHub Desktop.
function etag(options) {
return function etag(ctx, next) {
return next()
// `getResponseEntity` checks to see if the response has a body, and
// stringifies it depending on what kind of body it has (JSON, HTML,
// image, etc)
.then(() => getResponseEntity(ctx))
// `setEtag` calculates the ETag from the response body if it exists,
// then sets that ETag as a header
.then(entity => setEtag(ctx, entity, options));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment