Dragonfly2 icon indicating copy to clipboard operation
Dragonfly2 copied to clipboard

Support HTTP 301 and 307 Redirects with Cache-Control Logic in Backend HTTP Client

Open gaius-qi opened this issue 6 months ago • 6 comments

Description:

We need to enhance the backend HTTP client in Dragonfly to support HTTP 301 (Moved Permanently) and 307 (Temporary Redirect) redirects while adhering to the Cache-Control header logic. This improvement is crucial for optimizing blob downloads from Harbor.

Currently, when Dragonfly downloads blobs from Harbor using the provided Blobs URL, it initiates Range requests based on the Piece Length. However, Harbor's Blobs URL often redirects to an object storage URL, resulting in frequent 307 (Temporary Redirect) responses. Without proper handling of the Cache-Control header, Dragonfly repeatedly sends requests to Harbor, leading to increased load and inefficiency.

Problem:

Harbor Blobs URLs trigger multiple 307 redirects to object storage URLs. The backend HTTP client does not currently respect Cache-Control directives, which could otherwise reduce redundant requests to Harbor by caching redirect responses or respecting no-cache directives. Proposed Solution: Implement support for HTTP 301 and 307 redirects in Dragonfly's backend HTTP client. Ensure the client adheres to the Cache-Control header logic during redirects, such as caching redirect locations when allowed or avoiding caching when instructed (e.g., no-cache or no-store). Optimize Range requests to minimize unnecessary interactions with Harbor by leveraging cached redirect information when appropriate.

Expected Benefits:

Reduced number of requests to Harbor due to proper handling of cached redirect responses. Improved download performance and efficiency for blobs redirected to object storage. Better compliance with HTTP standards for redirects and caching. Additional Context: This feature is particularly important for scenarios involving Harbor and object storage integrations, where redirects are common. The implementation should handle edge cases such as invalid or missing Cache-Control headers and ensure that Range requests continue to function correctly after redirects.

Task:

Update the HTTP client in Dragonfly to handle 301 and 307 redirects. Implement logic to parse and respect Cache-Control headers during redirects. Add relevant tests to verify correct behavior for redirect caching and Range requests. Document the behavior and any configuration options for users.

Link:

  • Backend HTTP Client: https://github.com/dragonflyoss/client/blob/main/dragonfly-client-backend/src/http.rs

gaius-qi avatar May 26 '25 09:05 gaius-qi

PR is welcome!

gaius-qi avatar May 26 '25 10:05 gaius-qi

Hey there! I am new to this project. I see its due next month end. I am happy to take this issue and raise pr.

So I have checked the headers are already defined here https://github.com/dragonflyoss/dragonfly/blob/main/pkg/source/clients/httpprotocol/header.go#L22 but not implemented.

And whenever we make doRequest here https://github.com/dragonflyoss/dragonfly/blob/main/pkg/source/clients/httpprotocol/http_source_client.go#L258, we need to handle the new cache-control logic.

It would be great if you assign the issue to me before I start working on it. Thanks @gaius-qi

vignesh-codes avatar May 28 '25 23:05 vignesh-codes

Hey there! I am new to this project. I see its due next month end. I am happy to take this issue and raise pr.

So I have checked the headers are already defined here https://github.com/dragonflyoss/dragonfly/blob/main/pkg/source/clients/httpprotocol/header.go#L22 but not implemented.

And whenever we make doRequest here https://github.com/dragonflyoss/dragonfly/blob/main/pkg/source/clients/httpprotocol/http_source_client.go#L258, we need to handle the new cache-control logic.

It would be great if you assign the issue to me before I start working on it. Thanks @gaius-qi

The feature needs to implement in the Backend HTTP Client, refer to https://github.com/dragonflyoss/client/blob/main/dragonfly-client-backend/src/http.rs. If you can implement it, I will assign it to you.

gaius-qi avatar May 29 '25 01:05 gaius-qi

@gaius-qi sorry. i am not quite proficient in rust :/ Good luck!

vignesh-codes avatar May 29 '25 04:05 vignesh-codes

Hi @gaius-qi , I'd be interested in tackling this!

Manmeetkaur1525 avatar Jun 04 '25 18:06 Manmeetkaur1525

Hi @gaius-qi , I'd be interested in tackling this!

@Manmeetkaur1525

I have assigned it to you.

gaius-qi avatar Jun 05 '25 03:06 gaius-qi

Hi @gaius-qi, can I work on this issue?

jhukkk avatar Nov 05 '25 23:11 jhukkk

Hi @gaius-qi, can I work on this issue?

@jhukkk Assign to you.

gaius-qi avatar Nov 10 '25 20:11 gaius-qi