@@ -562,13 +562,13 @@ impl Http1Transaction for Server {
562
562
}
563
563
}
564
564
None | Some ( BodyLength :: Known ( 0 ) ) => {
565
- if msg. head . subject != StatusCode :: NOT_MODIFIED {
565
+ if Server :: can_have_content_length ( msg. req_method , msg . head . subject ) {
566
566
extend ( dst, b"content-length: 0\r \n " ) ;
567
567
}
568
568
Encoder :: length ( 0 )
569
569
}
570
570
Some ( BodyLength :: Known ( len) ) => {
571
- if msg. head . subject == StatusCode :: NOT_MODIFIED {
571
+ if ! Server :: can_have_content_length ( msg. req_method , msg . head . subject ) {
572
572
Encoder :: length ( 0 )
573
573
} else {
574
574
extend ( dst, b"content-length: " ) ;
@@ -638,13 +638,22 @@ impl Server {
638
638
if method == & Some ( Method :: HEAD ) || method == & Some ( Method :: CONNECT ) && status. is_success ( )
639
639
{
640
640
false
641
+ } else if status. is_informational ( ) {
642
+ false
643
+ } else {
644
+ match status {
645
+ StatusCode :: NO_CONTENT | StatusCode :: NOT_MODIFIED => false ,
646
+ _ => true ,
647
+ }
648
+ }
649
+ }
650
+
651
+ fn can_have_content_length ( method : & Option < Method > , status : StatusCode ) -> bool {
652
+ if status. is_informational ( ) || method == & Some ( Method :: CONNECT ) && status. is_success ( ) {
653
+ false
641
654
} else {
642
655
match status {
643
- // TODO: support for 1xx codes needs improvement everywhere
644
- // would be 100...199 => false
645
- StatusCode :: SWITCHING_PROTOCOLS
646
- | StatusCode :: NO_CONTENT
647
- | StatusCode :: NOT_MODIFIED => false ,
656
+ StatusCode :: NO_CONTENT | StatusCode :: NOT_MODIFIED => false ,
648
657
_ => true ,
649
658
}
650
659
}
0 commit comments