Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core/src/raw/http_util/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use http::Request;
use http::Response;

use super::body::IncomingAsyncBody;
use super::parse_content_encoding;
use super::parse_content_length;
use super::AsyncBody;
use crate::raw::*;
Expand Down Expand Up @@ -167,11 +168,13 @@ impl HttpClient {
})?;

// Get content length from header so that we can check it.
// If the request method is HEAD, we will ignore this.
let content_length = if is_head {
//
// - If the request method is HEAD, we will ignore content length.
// - If response contains content_encoding, we should omit it's content length.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose that update the comment to mention that this trick would only be available in WASM32

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to submit a PR to improve it 💌

let content_length = if is_head || parse_content_encoding(resp.headers())?.is_some() {
None
} else {
parse_content_length(resp.headers()).expect("response content length must be valid")
parse_content_length(resp.headers())?
};

let mut hr = Response::builder()
Expand Down
7 changes: 6 additions & 1 deletion core/src/raw/http_util/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use base64::engine::general_purpose;
use base64::Engine;
use chrono::DateTime;
use chrono::Utc;
use http::header::CACHE_CONTROL;
use http::header::CONTENT_DISPOSITION;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_RANGE;
use http::header::CONTENT_TYPE;
use http::header::ETAG;
use http::header::LAST_MODIFIED;
use http::header::LOCATION;
use http::header::{CACHE_CONTROL, CONTENT_ENCODING};
use http::HeaderValue;
use http::{HeaderMap, HeaderName};
use md5::Digest;
Expand Down Expand Up @@ -77,6 +77,11 @@ pub fn parse_content_type(headers: &HeaderMap) -> Result<Option<&str>> {
parse_header_to_str(headers, CONTENT_TYPE)
}

/// Parse content encoding from header map.
pub fn parse_content_encoding(headers: &HeaderMap) -> Result<Option<&str>> {
parse_header_to_str(headers, CONTENT_ENCODING)
}

/// Parse content range from header map.
pub fn parse_content_range(headers: &HeaderMap) -> Result<Option<BytesContentRange>> {
parse_header_to_str(headers, CONTENT_RANGE)?
Expand Down
1 change: 1 addition & 0 deletions core/src/raw/http_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub use header::format_authorization_by_basic;
pub use header::format_authorization_by_bearer;
pub use header::format_content_md5;
pub use header::parse_content_disposition;
pub use header::parse_content_encoding;
pub use header::parse_content_length;
pub use header::parse_content_md5;
pub use header::parse_content_range;
Expand Down