feat(core): improve HeaderValue compatibility, closes #2162 (#2438)

This commit is contained in:
Lucas Fernandes Nogueira 2021-08-15 18:14:40 -03:00 committed by GitHub
parent 6be3f43391
commit 1635798a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 15 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch
---
Use `HeaderValue::from_bytes` instead of `HeaderValue::from_str` and `HeaderValue#to_bytes` instead of `HeaderValue#to_str` to improve compatibility.

View File

@ -34,43 +34,43 @@ pub enum Error {
#[error("Network Error: {0}")]
Network(#[from] reqwest::Error),
/// HTTP method error.
#[error("{0}")]
#[error(transparent)]
HttpMethod(#[from] http::method::InvalidMethod),
/// Invalid HTTP header value.
#[cfg(feature = "reqwest-client")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "reqwest-client")))]
#[error("{0}")]
#[error(transparent)]
HttpHeaderValue(#[from] http::header::InvalidHeaderValue),
/// Invalid HTTP header value.
#[error("{0}")]
#[error(transparent)]
HttpHeader(#[from] http::header::InvalidHeaderName),
/// Failed to serialize header value as string.
#[error("failed to convert response header value to string")]
HttpHeaderToString(#[from] http::header::ToStrError),
#[error(transparent)]
Utf8(#[from] std::string::FromUtf8Error),
/// HTTP form to must be an object.
#[error("http form must be an object")]
InvalidHttpForm,
/// Semver error.
#[error("{0}")]
#[error(transparent)]
Semver(#[from] semver::Error),
/// JSON error.
#[error("{0}")]
#[error(transparent)]
Json(#[from] serde_json::Error),
/// Bincode error.
#[error("{0}")]
#[error(transparent)]
Bincode(#[from] Box<bincode::ErrorKind>),
/// IO error.
#[error("{0}")]
#[error(transparent)]
Io(#[from] std::io::Error),
/// Ignore error.
#[error("failed to walkdir: {0}")]
Ignore(#[from] ignore::Error),
/// ZIP error.
#[error("{0}")]
#[error(transparent)]
Zip(#[from] zip::result::ZipError),
/// Notification error.
#[cfg(notification_all)]
#[error("{0}")]
#[error(transparent)]
Notification(#[from] notify_rust::error::Error),
/// failed to detect the current platform.
#[error("failed to detect platform: {0}")]

View File

@ -88,8 +88,10 @@ impl Client {
if let Some(headers) = request.headers {
for (header, header_value) in headers.iter() {
request_builder =
request_builder.header(HeaderName::from_bytes(header.as_bytes())?, header_value);
request_builder = request_builder.header(
HeaderName::from_bytes(header.as_bytes())?,
header_value.as_bytes(),
);
}
}
@ -169,7 +171,7 @@ impl Client {
for (header, value) in headers.iter() {
http_request.headers_mut().insert(
HeaderName::from_bytes(header.as_bytes())?,
http::header::HeaderValue::from_str(value)?,
http::header::HeaderValue::from_bytes(value.as_bytes())?,
);
}
}
@ -348,7 +350,10 @@ impl Response {
let mut headers = HashMap::new();
for (name, value) in self.1.headers() {
headers.insert(name.as_str().to_string(), value.to_str()?.to_string());
headers.insert(
name.as_str().to_string(),
String::from_utf8(value.as_bytes().to_vec())?,
);
}
let status = self.1.status().as_u16();