Skip to content

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

Merged
baszalmstra merged 1 commit intoprefix-dev:mainfrom
zanieb:zb/headers
Feb 23, 2024
Merged

feat: Allow extra headers to be attached to requests#9
baszalmstra merged 1 commit intoprefix-dev:mainfrom
zanieb:zb/headers

Conversation

@zanieb
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Nvm CI I have to fix the workflow

@baszalmstra baszalmstra merged commit 1400918 into prefix-dev:main Feb 23, 2024
@github-actions github-actions bot mentioned this pull request Feb 23, 2024
@zanieb
Copy link
Copy Markdown
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