@@ -31,13 +31,7 @@ var querystring = require('querystring');
3131 * @api private
3232 */
3333
34- exports . etag = function ( body , encoding ) {
35- var buf = ! Buffer . isBuffer ( body )
36- ? new Buffer ( body , encoding )
37- : body ;
38-
39- return etag ( buf , { weak : false } ) ;
40- } ;
34+ exports . etag = createETagGenerator ( { weak : false } )
4135
4236/**
4337 * Return weak ETag for `body`.
@@ -48,13 +42,7 @@ exports.etag = function (body, encoding) {
4842 * @api private
4943 */
5044
51- exports . wetag = function wetag ( body , encoding ) {
52- var buf = ! Buffer . isBuffer ( body )
53- ? new Buffer ( body , encoding )
54- : body ;
55-
56- return etag ( buf , { weak : true } ) ;
57- } ;
45+ exports . wetag = createETagGenerator ( { weak : true } )
5846
5947/**
6048 * Check if `path` looks absolute.
@@ -273,6 +261,25 @@ exports.setCharset = function setCharset(type, charset) {
273261 return contentType . format ( parsed ) ;
274262} ;
275263
264+ /**
265+ * Create an ETag generator function, generating ETags with
266+ * the given options.
267+ *
268+ * @param {object } options
269+ * @return {function }
270+ * @private
271+ */
272+
273+ function createETagGenerator ( options ) {
274+ return function generateETag ( body , encoding ) {
275+ var buf = ! Buffer . isBuffer ( body )
276+ ? new Buffer ( body , encoding )
277+ : body
278+
279+ return etag ( buf , options )
280+ }
281+ }
282+
276283/**
277284 * Parse an extended query string with qs.
278285 *
0 commit comments