feat: if download by range, add content-range header to resopnse header (#244)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
bb04710963
commit
a7957a99bb
|
|
@ -553,6 +553,7 @@ dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hashring",
|
"hashring",
|
||||||
|
"headers 0.4.0",
|
||||||
"hex",
|
"hex",
|
||||||
"home",
|
"home",
|
||||||
"hostname",
|
"hostname",
|
||||||
|
|
@ -916,13 +917,28 @@ checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bytes",
|
"bytes",
|
||||||
"headers-core",
|
"headers-core 0.2.0",
|
||||||
"http 0.2.11",
|
"http 0.2.11",
|
||||||
"httpdate",
|
"httpdate",
|
||||||
"mime",
|
"mime",
|
||||||
"sha1",
|
"sha1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "headers"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "322106e6bd0cba2d5ead589ddb8150a13d7c4217cf80d7c4f682ca994ccc6aa9"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"bytes",
|
||||||
|
"headers-core 0.3.0",
|
||||||
|
"http 1.0.0",
|
||||||
|
"httpdate",
|
||||||
|
"mime",
|
||||||
|
"sha1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "headers-core"
|
name = "headers-core"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
@ -932,6 +948,15 @@ dependencies = [
|
||||||
"http 0.2.11",
|
"http 0.2.11",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "headers-core"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4"
|
||||||
|
dependencies = [
|
||||||
|
"http 1.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
|
|
@ -3252,7 +3277,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"headers",
|
"headers 0.3.9",
|
||||||
"http 0.2.11",
|
"http 0.2.11",
|
||||||
"hyper 0.14.28",
|
"hyper 0.14.28",
|
||||||
"log",
|
"log",
|
||||||
|
|
|
||||||
|
|
@ -86,3 +86,4 @@ http-body-util = "0.1.0"
|
||||||
regex = "1.10.2"
|
regex = "1.10.2"
|
||||||
http-range-header = "0.4.0"
|
http-range-header = "0.4.0"
|
||||||
futures-util = "0.3.30"
|
futures-util = "0.3.30"
|
||||||
|
headers = "0.4.0"
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,10 @@ pub enum Error {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
TonicStatus(#[from] tonic::Status),
|
TonicStatus(#[from] tonic::Status),
|
||||||
|
|
||||||
|
// HeaderError is the error for headers.
|
||||||
|
#[error(transparent)]
|
||||||
|
HeadersError(#[from] headers::Error),
|
||||||
|
|
||||||
// Reqwest is the error for reqwest.
|
// Reqwest is the error for reqwest.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Reqwest(#[from] reqwest::Error),
|
Reqwest(#[from] reqwest::Error),
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,21 @@ impl Task {
|
||||||
return Err(Error::InvalidContentLength());
|
return Err(Error::InvalidContentLength());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If download range is specified, insert the content range header
|
||||||
|
// to the resopnse header.
|
||||||
|
let mut response_header = task.response_header.clone();
|
||||||
|
if let Some(range) = download.range.clone() {
|
||||||
|
response_header.insert(
|
||||||
|
reqwest::header::CONTENT_RANGE.to_string(),
|
||||||
|
format!(
|
||||||
|
"bytes {}-{}/{}",
|
||||||
|
range.start,
|
||||||
|
range.start + range.length - 1,
|
||||||
|
content_length
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Send the download task started request.
|
// Send the download task started request.
|
||||||
download_progress_tx
|
download_progress_tx
|
||||||
.send_timeout(
|
.send_timeout(
|
||||||
|
|
@ -197,7 +212,7 @@ impl Task {
|
||||||
download_task_response::Response::DownloadTaskStartedResponse(
|
download_task_response::Response::DownloadTaskStartedResponse(
|
||||||
dfdaemon::v2::DownloadTaskStartedResponse {
|
dfdaemon::v2::DownloadTaskStartedResponse {
|
||||||
content_length,
|
content_length,
|
||||||
response_header: task.response_header.clone(),
|
response_header,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue