@@ -1687,6 +1687,51 @@ fn http2_service_poll_ready_error_sends_goaway() {
1687
1687
assert_eq ! ( h2_err. reason( ) , Some ( h2:: Reason :: INADEQUATE_SECURITY ) ) ;
1688
1688
}
1689
1689
1690
+ #[ test]
1691
+ fn skips_content_length_for_304_responses ( ) {
1692
+ let server = serve ( ) ;
1693
+ server. reply ( )
1694
+
1695
+ . status ( hyper:: StatusCode :: NOT_MODIFIED )
1696
+ . body ( "foo" ) ;
1697
+ let mut req = connect ( server. addr ( ) ) ;
1698
+ req. write_all ( b"\
1699
+ GET / HTTP/1.1\r \n \
1700
+ Host: example.domain\r \n \
1701
+ Connection: close\r \n \
1702
+ \r \n \
1703
+ ") . unwrap ( ) ;
1704
+
1705
+ let mut response = String :: new ( ) ;
1706
+ req. read_to_string ( & mut response) . unwrap ( ) ;
1707
+ assert ! ( !response. contains( "content-length:" ) ) ;
1708
+ }
1709
+
1710
+ #[ test]
1711
+ fn skips_content_length_and_body_for_304_responses ( ) {
1712
+ let server = serve ( ) ;
1713
+ server. reply ( )
1714
+
1715
+ . status ( hyper:: StatusCode :: NOT_MODIFIED )
1716
+ . body ( "foo" ) ;
1717
+ let mut req = connect ( server. addr ( ) ) ;
1718
+ req. write_all ( b"\
1719
+ GET / HTTP/1.1\r \n \
1720
+ Host: example.domain\r \n \
1721
+ Connection: close\r \n \
1722
+ \r \n \
1723
+ ") . unwrap ( ) ;
1724
+
1725
+ let mut response = String :: new ( ) ;
1726
+ req. read_to_string ( & mut response) . unwrap ( ) ;
1727
+ assert ! ( !response. contains( "content-length:" ) ) ;
1728
+ let mut lines = response. lines ( ) ;
1729
+ assert_eq ! ( lines. next( ) , Some ( "HTTP/1.1 304 Not Modified" ) ) ;
1730
+
1731
+ let mut lines = lines. skip_while ( |line| !line. is_empty ( ) ) ;
1732
+ assert_eq ! ( lines. next( ) , Some ( "" ) ) ;
1733
+ assert_eq ! ( lines. next( ) , None ) ;
1734
+ }
1690
1735
// -------------------------------------------------
1691
1736
// the Server that is used to run all the tests with
1692
1737
// -------------------------------------------------
@@ -2058,4 +2103,3 @@ impl Drop for Dropped {
2058
2103
self . 0 . store ( true , Ordering :: SeqCst ) ;
2059
2104
}
2060
2105
}
2061
-
0 commit comments