Skip to content

Commit

Permalink
feat: add http headers to cli (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored Nov 4, 2024
1 parent db8ce8b commit fa1d83d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- `--http-header` CLI argument ([#238](https://github.com/stac-utils/stac-asset/pull/238))

## [0.4.5] - 2024-10-29

### Added
Expand Down
16 changes: 16 additions & 0 deletions src/stac_asset/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def cli() -> None:
help="Total number of seconds for the whole request",
default=DEFAULT_HTTP_CLIENT_TIMEOUT,
)
@click.option(
"--http-header",
"http_headers",
help="key=value header pairs to use when making HTTP requests",
multiple=True,
)
@click.option(
"-k",
"--keep",
Expand Down Expand Up @@ -169,6 +175,7 @@ def download(
s3_max_attempts: int,
http_max_attempts: int,
http_timeout: int,
http_headers: list[str],
keep: bool,
fail_fast: bool,
overwrite: bool,
Expand Down Expand Up @@ -217,6 +224,7 @@ def download(
s3_max_attempts,
http_max_attempts,
http_timeout,
http_headers=http_headers,
keep=keep,
fail_fast=fail_fast,
overwrite=overwrite,
Expand All @@ -240,12 +248,20 @@ async def download_async(
s3_max_attempts: int,
http_max_attempts: int,
http_timeout: int,
http_headers: list[str],
keep: bool,
fail_fast: bool,
overwrite: bool,
max_concurrent_downloads: int,
stream: bool | None,
) -> None:
http_headers_dict = {}
for http_header in http_headers:
values = http_header.split("=", 1)
if len(values) == 2:
http_headers_dict[values[0]] = values[1]
else:
http_headers_dict[values[0]] = ""
config = Config(
alternate_assets=alternate_assets,
include=include,
Expand Down

0 comments on commit fa1d83d

Please sign in to comment.