File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,10 @@ internals.marshal = function (request, next) {
112
112
// Set empty stream
113
113
114
114
response . _payload = new internals . Empty ( ) ;
115
- delete response . headers [ 'content-length' ] ;
115
+ if ( request . method !== 'head' ) {
116
+ delete response . headers [ 'content-length' ] ;
117
+ }
118
+
116
119
return Auth . response ( request , next ) ; // Must be last in case requires access to headers
117
120
}
118
121
Original file line number Diff line number Diff line change @@ -1656,6 +1656,25 @@ describe('transmission', function () {
1656
1656
} ) ;
1657
1657
} ) ;
1658
1658
1659
+ it ( 'head request retains content-length header' , function ( done ) {
1660
+
1661
+ var server = new Hapi . Server ( ) ;
1662
+ server . connection ( ) ;
1663
+ var handler = function ( request , reply ) {
1664
+
1665
+ return reply ( 'x' ) . bytes ( 1 ) ;
1666
+ } ;
1667
+
1668
+ server . route ( { method : 'GET' , path : '/' , handler : handler } ) ;
1669
+
1670
+ server . inject ( { method : 'HEAD' , url : '/' } , function ( res ) {
1671
+
1672
+ expect ( res . statusCode ) . to . equal ( 200 ) ;
1673
+ expect ( res . headers [ 'content-length' ] ) . to . equal ( 1 ) ;
1674
+ done ( ) ;
1675
+ } ) ;
1676
+ } ) ;
1677
+
1659
1678
describe ( 'response range' , function ( ) {
1660
1679
1661
1680
var fileStreamHandler = function ( request , reply ) {
You can’t perform that action at this time.
0 commit comments