|
1 | 1 | use std::fmt::{self, Write};
|
2 | 2 | use std::mem::MaybeUninit;
|
3 | 3 |
|
4 |
| -#[cfg(all(feature = "server", feature = "runtime"))] |
5 |
| -use tokio::time::Instant; |
6 | 4 | #[cfg(any(test, feature = "server", feature = "ffi"))]
|
7 | 5 | use bytes::Bytes;
|
8 | 6 | use bytes::BytesMut;
|
9 | 7 | #[cfg(feature = "server")]
|
10 | 8 | use http::header::ValueIter;
|
11 | 9 | use http::header::{self, Entry, HeaderName, HeaderValue};
|
12 | 10 | use http::{HeaderMap, Method, StatusCode, Version};
|
| 11 | +#[cfg(all(feature = "server", feature = "runtime"))] |
| 12 | +use tokio::time::Instant; |
13 | 13 | use tracing::{debug, error, trace, trace_span, warn};
|
14 | 14 |
|
15 | 15 | use crate::body::DecodedLength;
|
@@ -487,6 +487,10 @@ impl Server {
|
487 | 487 | }
|
488 | 488 | }
|
489 | 489 |
|
| 490 | + fn can_have_implicit_zero_content_length(method: &Option<Method>, status: StatusCode) -> bool { |
| 491 | + Server::can_have_content_length(method, status) && method != &Some(Method::HEAD) |
| 492 | + } |
| 493 | + |
490 | 494 | fn encode_headers_with_lower_case(
|
491 | 495 | msg: Encode<'_, StatusCode>,
|
492 | 496 | dst: &mut Vec<u8>,
|
@@ -839,7 +843,10 @@ impl Server {
|
839 | 843 | }
|
840 | 844 | }
|
841 | 845 | None | Some(BodyLength::Known(0)) => {
|
842 |
| - if Server::can_have_content_length(msg.req_method, msg.head.subject) { |
| 846 | + if Server::can_have_implicit_zero_content_length( |
| 847 | + msg.req_method, |
| 848 | + msg.head.subject, |
| 849 | + ) { |
843 | 850 | header_name_writer.write_full_header_line(
|
844 | 851 | dst,
|
845 | 852 | "content-length: 0\r\n",
|
@@ -1033,7 +1040,7 @@ impl Http1Transaction for Client {
|
1033 | 1040 | }
|
1034 | 1041 |
|
1035 | 1042 | #[cfg(feature = "ffi")]
|
1036 |
| - if let Some(ref mut header_order) = header_order { |
| 1043 | + if let Some(ref mut header_order) = header_order { |
1037 | 1044 | header_order.append(&name);
|
1038 | 1045 | }
|
1039 | 1046 |
|
|
0 commit comments