Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new etaging options #30

Merged
merged 9 commits into from Oct 18, 2015
Merged

Add new etaging options #30

merged 9 commits into from Oct 18, 2015

Conversation

@kanongil
Copy link
Member

kanongil commented Jul 13, 2015

This PR adds a new etagMethod option to the file and directory handlers, as suggested in #29:

  • etagMethod - specifies the method used to calculate the ETag header response. Available values:
    • 'hash' - SHA1 sum of the file contents, suitable for distributed deployments. Default value.
    • 'simple' - Hex encoded size and modification date, suitable when files are only stored on a single server.
    • false - Disable ETag computation.

Note that this changes the behavior of the default hashing method to always return an ETag header. This requires uncached etags to be computed in the prepare step, which translates to some extra latency in such requests, while the file is hashed. I don't believe that this should cause problems for most common use-cases and can actually improve performance in some cases (eg. cached if-none-match requests against a freshly started server can now serve a 304 response).

@kanongil kanongil added the feature label Jul 13, 2015
@kanongil

This comment has been minimized.

Copy link
Member Author

kanongil commented Jul 29, 2015

PR updated with a deferred callback mechanism to prevent multiple hashings on the same file.

lib/etag.js Outdated
var internals = {};


internals.computeHashed = function (response, stat, callback) {

This comment has been minimized.

Copy link
@hueniverse

hueniverse Jul 29, 2015

Member

Change callback to next since it is not always called on next tick or if it needs to be consistent, use Hoek.nextTick().

lib/etag.js Outdated
return callbacks.push(callback);
}

pendings[pendingsId] = callbacks = [callback];

This comment has been minimized.

Copy link
@hueniverse

hueniverse Jul 29, 2015

Member

Break into two assignment statements to improve readability.

@hueniverse

This comment has been minimized.

Copy link
Member

hueniverse commented Jul 29, 2015

See comments. Otherwise looks good.

@hueniverse hueniverse self-assigned this Jul 29, 2015
@hueniverse hueniverse added this to the 2.1.7 milestone Jul 29, 2015
@kanongil kanongil modified the milestones: 3.0.0, 3.1.0 Aug 8, 2015
@kanongil kanongil force-pushed the kanongil:etag-option branch from c691587 to abcafee Aug 12, 2015
@kanongil kanongil force-pushed the kanongil:etag-option branch from 46b3372 to 7f5c0e0 Oct 18, 2015
kanongil added a commit that referenced this pull request Oct 18, 2015
Add new etaging options
@kanongil kanongil merged commit 478e66c into hapijs:master Oct 18, 2015
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.