feat: add task ID response header in Dragonfly client proxy (#1256)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
777c131fbe
commit
bf6f49e0e9
|
|
@ -79,11 +79,15 @@ pub const DRAGONFLY_PIECE_LENGTH_HEADER: &str = "X-Dragonfly-Piece-Length";
|
|||
pub const DRAGONFLY_CONTENT_FOR_CALCULATING_TASK_ID_HEADER: &str =
|
||||
"X-Dragonfly-Content-For-Calculating-Task-ID";
|
||||
|
||||
/// DRAGONFLY_TASK_DOWNLOAD_FINISHED_HEADER is the header key to indicate whether the task download finished.
|
||||
/// DRAGONFLY_TASK_DOWNLOAD_FINISHED_HEADER is the response header key to indicate whether the task download finished.
|
||||
/// When the task download is finished, the response will include this header with the value `"true"`,
|
||||
/// indicating that the download hit the local cache.
|
||||
pub const DRAGONFLY_TASK_DOWNLOAD_FINISHED_HEADER: &str = "X-Dragonfly-Task-Download-Finished";
|
||||
|
||||
/// DRAGONFLY_TASK_ID_HEADER is the response header key of task id. Client will calculate the task ID
|
||||
/// based on `url`, `piece_length`, `tag`, `application`, and `filtered_query_params`.
|
||||
pub const DRAGONFLY_TASK_ID_HEADER: &str = "X-Dragonfly-Task-ID";
|
||||
|
||||
/// get_tag gets the tag from http header.
|
||||
pub fn get_tag(header: &HeaderMap) -> Option<String> {
|
||||
header
|
||||
|
|
|
|||
|
|
@ -768,7 +768,10 @@ async fn proxy_via_dfdaemon(
|
|||
|
||||
// Construct the response.
|
||||
let mut response = Response::new(boxed_body);
|
||||
*response.headers_mut() = make_response_headers(download_task_started_response.clone())?;
|
||||
*response.headers_mut() = make_response_headers(
|
||||
message.task_id.as_str(),
|
||||
download_task_started_response.clone(),
|
||||
)?;
|
||||
*response.status_mut() = http::StatusCode::OK;
|
||||
|
||||
// Return the response if the client return the first piece.
|
||||
|
|
@ -1151,6 +1154,7 @@ fn make_download_url(
|
|||
|
||||
/// make_response_headers makes the response headers.
|
||||
fn make_response_headers(
|
||||
task_id: &str,
|
||||
mut download_task_started_response: DownloadTaskStartedResponse,
|
||||
) -> ClientResult<hyper::header::HeaderMap> {
|
||||
// Insert the content range header to the response header.
|
||||
|
|
@ -1178,6 +1182,11 @@ fn make_response_headers(
|
|||
);
|
||||
}
|
||||
|
||||
download_task_started_response.response_header.insert(
|
||||
header::DRAGONFLY_TASK_ID_HEADER.to_string(),
|
||||
task_id.to_string(),
|
||||
);
|
||||
|
||||
hashmap_to_headermap(&download_task_started_response.response_header)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue