Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow extra headers to be attached to requests #9

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

zanieb
Copy link
Contributor

@zanieb zanieb commented Feb 23, 2024

Because the target URL for requests made during range reads are constructed from the response URL, they lose credentials attached to the URL. This change allows extra headers to be attached to the requests so users can propagate important headers (such as authorization)

Usage looks roughly like this...

let req = client
    .head(url.clone())
    .build()?

// Copy authorization headers from the HEAD request to subsequent requests
let mut headers = HeaderMap::default();
if let Some(authorization) = req.headers().get("authorization") {
    headers.append("authorization", authorization.clone());
}

let mut reader =
    AsyncHttpRangeReader::from_head_response(client, response, headers)
        .await?;

An alternative option would be to copy authentication from the request URL to the response URL (as in astral-sh/uv#1874 / uv-auth)

Note this is a breaking API change, I don't see an easy way around it e.g. a helper method like with_headers doesn't seem feasible with the way the type is designed.

Needed to resolve astral-sh/uv#1709

@zanieb zanieb changed the title Allow extra headers to be attached to requests feat: Allow extra headers to be attached to requests Feb 23, 2024
Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, if you can fix CI Id be happy to press the green button.

Thanks!

@baszalmstra
Copy link
Collaborator

Nvm CI I have to fix the workflow

@baszalmstra baszalmstra merged commit 1400918 into prefix-dev:main Feb 23, 2024
6 of 7 checks passed
@github-actions github-actions bot mentioned this pull request Feb 23, 2024
@zanieb
Copy link
Contributor Author

zanieb commented Feb 23, 2024

Thanks for the quick merge and release — let me know if you want me to do more i.e. update the tests

(nevermind I see d0530eb now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uv pip install resulting in 401 Unauthorized with private index url
2 participants