@@ -550,13 +550,13 @@ impl Http1Transaction for Server {
550
550
}
551
551
}
552
552
None | Some ( BodyLength :: Known ( 0 ) ) => {
553
- if msg. head . subject != StatusCode :: NOT_MODIFIED {
553
+ if Server :: can_have_content_length ( msg. req_method , msg . head . subject ) {
554
554
extend ( dst, b"content-length: 0\r \n " ) ;
555
555
}
556
556
Encoder :: length ( 0 )
557
557
}
558
558
Some ( BodyLength :: Known ( len) ) => {
559
- if msg. head . subject == StatusCode :: NOT_MODIFIED {
559
+ if ! Server :: can_have_content_length ( msg. req_method , msg . head . subject ) {
560
560
Encoder :: length ( 0 )
561
561
} else {
562
562
extend ( dst, b"content-length: " ) ;
@@ -625,13 +625,22 @@ impl Server {
625
625
if method == & Some ( Method :: HEAD ) || method == & Some ( Method :: CONNECT ) && status. is_success ( )
626
626
{
627
627
false
628
+ } else if status. is_informational ( ) {
629
+ false
630
+ } else {
631
+ match status {
632
+ StatusCode :: NO_CONTENT | StatusCode :: NOT_MODIFIED => false ,
633
+ _ => true ,
634
+ }
635
+ }
636
+ }
637
+
638
+ fn can_have_content_length ( method : & Option < Method > , status : StatusCode ) -> bool {
639
+ if status. is_informational ( ) || method == & Some ( Method :: CONNECT ) && status. is_success ( ) {
640
+ false
628
641
} else {
629
642
match status {
630
- // TODO: support for 1xx codes needs improvement everywhere
631
- // would be 100...199 => false
632
- StatusCode :: SWITCHING_PROTOCOLS
633
- | StatusCode :: NO_CONTENT
634
- | StatusCode :: NOT_MODIFIED => false ,
643
+ StatusCode :: NO_CONTENT | StatusCode :: NOT_MODIFIED => false ,
635
644
_ => true ,
636
645
}
637
646
}
0 commit comments