Skip to content

python(feat): let download_file forward extra headers to rest_client.get#677

Merged
ian-sift merged 2 commits into
mainfrom
eng-12468-download-file-extra-headers
Jul 10, 2026
Merged

python(feat): let download_file forward extra headers to rest_client.get#677
ian-sift merged 2 commits into
mainfrom
eng-12468-download-file-extra-headers

Conversation

@ian-sift

@ian-sift ian-sift commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Presigned S3-style URLs bind their signature to a specific Host authority. Callers that route the request through a container-internal alias — e.g. accessing local minio at s3:9090 from inside a docker container while the URL was signed against the browser-facing localhost:9090 — need to override the outbound Host header so the SigV4 check still validates. Today the only way is to bypass download_file entirely and reimplement streaming + auth stripping on top of a raw `requests.get`.

Add an optional extra_headers kwarg that merges on top of the internal Authorization: None strip:

  • Absent callers get identical behavior (100% backwards compatible; extra_headers defaults to None).
  • When present, callers can override Host, add a Range, supply a proxy-scoped Authorization, etc. without giving up the SDK's rest session or the streamed 4 MiB chunk loop.

Motivation

This is being landed to let the sift-stack/azimuth canvas file-attachment download path collapse its "local-dev loopback" and "production" branches into a single download_file(...) call. Right now that codebase carries a full parallel implementation (streamed requests.get + .part-file crash-safe rename) solely to inject one Host header.

Test plan

  • pytest lib/sift_client/_tests/_internal/util/test_file.py3 passed:
    • test_no_extra_headers_strips_only_authorization — default behavior unchanged
    • test_extra_headers_are_forwarded — merged headers reach rest_client.get
    • test_extra_headers_can_override_authorization_strip — caller-supplied Authorization wins (documented as "default, not invariant")

Downstream

Azimuth follow-up (blocked on this landing + a 0.19.x release, or on Sift's private packages gateway picking it up under the current version).

Made with Cursor

Presigned S3-style URLs bind their signature to a specific Host
authority. Callers that route the request through a container-
internal alias (e.g. accessing local minio at `s3:9090` from inside
a pyworker container while the URL was signed against the browser-
facing `localhost:9090`) need to override the outbound `Host` header
so the SigV4 check still validates. Today the only way is to bypass
`download_file` entirely and reimplement streaming + auth stripping
on top of a raw `requests.get`.

Add an optional `extra_headers` kwarg that merges on top of the
internal `Authorization: None` strip. Absent callers get identical
behavior. When present, callers can override Host, add a Range,
supply a proxy-scoped Authorization, etc. without giving up the
SDK's rest session or the streamed chunk loop.

Tests cover: (a) default behavior unchanged, (b) merged headers
forwarded verbatim, and (c) caller-supplied Authorization wins
over the strip when explicitly set (documented as a "default,
not invariant" property).

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Python docs preview: https://sift-stack.github.io/sift/python/pr-677/

Deployed from 8e57d00. The link may take up to a minute to become live as GitHub Pages propagates.

alexluck-sift
alexluck-sift previously approved these changes Jul 9, 2026
@ian-sift
ian-sift enabled auto-merge (squash) July 9, 2026 23:25
@alexluck-sift
alexluck-sift self-requested a review July 10, 2026 00:22
@ian-sift
ian-sift merged commit 3dda37a into main Jul 10, 2026
26 checks passed
@ian-sift
ian-sift deleted the eng-12468-download-file-extra-headers branch July 10, 2026 00:22
alexluck-sift pushed a commit that referenced this pull request Jul 11, 2026
Bump version to 0.19.0 and update the changelog for the PRs merged
since v0.18.0: ABAC attributes (#646), get_data cache improvements
(#650), pytest docstring cleaning (#658), ULog data imports (#663),
access control API grouping (#666), report templates (#672),
download_file extra headers (#677), and the get_data pagination fix
plus progress bars (#678).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5U49rrpvQm5bPbvEjR4xr
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.

2 participants