1
+ /*!
2
+ * express
3
+ * Copyright(c) 2009-2013 TJ Holowaychuk
4
+ * Copyright(c) 2014-2015 Douglas Christopher Wilson
5
+ * MIT Licensed
6
+ */
7
+
1
8
/**
2
9
* Module dependencies.
10
+ * @api private
3
11
*/
4
12
5
13
var contentDisposition = require ( 'content-disposition' ) ;
@@ -86,7 +94,6 @@ res.links = function(links){
86
94
87
95
res . send = function ( body ) {
88
96
var req = this . req ;
89
- var head = 'HEAD' == req . method ;
90
97
var type ;
91
98
var encoding ;
92
99
var len ;
@@ -153,12 +160,12 @@ res.send = function(body){
153
160
this . set ( 'Content-Length' , len ) ;
154
161
}
155
162
156
- // ETag support
157
- var etag = len !== undefined && app . get ( 'etag fn' ) ;
158
- if ( etag && ( 'GET' === req . method || 'HEAD' === req . method ) ) {
159
- if ( ! this . get ( 'ETag' ) ) {
160
- etag = etag ( body , encoding ) ;
161
- etag && this . set ( 'ETag' , etag ) ;
163
+ // populate ETag
164
+ var etag ;
165
+ var generateETag = len !== undefined && app . get ( 'etag fn' ) ;
166
+ if ( typeof generateETag === 'function' && ! this . get ( 'ETag' ) ) {
167
+ if ( ( etag = generateETag ( body , encoding ) ) ) {
168
+ this . set ( 'ETag' , etag ) ;
162
169
}
163
170
}
164
171
@@ -173,8 +180,13 @@ res.send = function(body){
173
180
body = '' ;
174
181
}
175
182
176
- // respond
177
- this . end ( ( head ? null : body ) , encoding ) ;
183
+ if ( req . method === 'HEAD' ) {
184
+ // skip body for HEAD
185
+ this . end ( ) ;
186
+ } else {
187
+ // respond
188
+ this . end ( body , encoding ) ;
189
+ }
178
190
179
191
return this ;
180
192
} ;
0 commit comments