diff --git a/dragonfly-client/src/proxy/header.rs b/dragonfly-client/src/proxy/header.rs index e56b9885..11898023 100644 --- a/dragonfly-client/src/proxy/header.rs +++ b/dragonfly-client/src/proxy/header.rs @@ -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 { header diff --git a/dragonfly-client/src/proxy/mod.rs b/dragonfly-client/src/proxy/mod.rs index 2df3170b..04e56b3e 100644 --- a/dragonfly-client/src/proxy/mod.rs +++ b/dragonfly-client/src/proxy/mod.rs @@ -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 { // 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) }