File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -476,7 +476,9 @@ impl Http1Transaction for Server {
476476 } ,
477477 None |
478478 Some ( BodyLength :: Known ( 0 ) ) => {
479- extend ( dst, b"content-length: 0\r \n " ) ;
479+ if msg. head . subject != StatusCode :: NOT_MODIFIED {
480+ extend ( dst, b"content-length: 0\r \n " ) ;
481+ }
480482 Encoder :: length ( 0 )
481483 } ,
482484 Some ( BodyLength :: Known ( len) ) => {
@@ -1591,4 +1593,3 @@ mod tests {
15911593 } )
15921594 }
15931595}
1594-
Original file line number Diff line number Diff line change @@ -1687,6 +1687,24 @@ fn http2_service_poll_ready_error_sends_goaway() {
16871687 assert_eq ! ( h2_err. reason( ) , Some ( h2:: Reason :: INADEQUATE_SECURITY ) ) ;
16881688}
16891689
1690+ #[ test]
1691+ fn skips_content_length_for_304_responses ( ) {
1692+ let server = serve ( ) ;
1693+ server. reply ( )
1694+ . status ( hyper:: StatusCode :: NOT_MODIFIED ) ;
1695+ let mut req = connect ( server. addr ( ) ) ;
1696+ req. write_all ( b"\
1697+ GET / HTTP/1.1\r \n \
1698+ Host: example.domain\r \n \
1699+ Connection: close\r \n \
1700+ \r \n \
1701+ ") . unwrap ( ) ;
1702+
1703+ let mut response = String :: new ( ) ;
1704+ req. read_to_string ( & mut response) . unwrap ( ) ;
1705+ assert ! ( !response. contains( "content-length:" ) ) ;
1706+ }
1707+
16901708// -------------------------------------------------
16911709// the Server that is used to run all the tests with
16921710// -------------------------------------------------
@@ -2058,4 +2076,3 @@ impl Drop for Dropped {
20582076 self . 0 . store ( true , Ordering :: SeqCst ) ;
20592077 }
20602078}
2061-
You can’t perform that action at this time.
0 commit comments