Skip to content

Mitlib extend custom request headers - #1

Open
ghukill wants to merge 2 commits into
mainfrom
mitlib-extend-custom-request-headers
Open

ghukill wants to merge 2 commits into
mainfrom
mitlib-extend-custom-request-headers

Conversation

@ghukill

@ghukill ghukill commented Oct 1, 2026 •

Copy link
Copy Markdown

Note

This PR is purely for internal MITLib review. This branch will not be merged locally to main. A PR will be created directly from this branch to the upstream repository when ready.

In support of ticket: https://mitlibraries.atlassian.net/browse/DSO-130.

The changes here do two primary things, broken down by commit:

  1. route bitstream updates through api_post()
  2. support custom headers on DSpaceClient init that get applied to all API HTTP requests

Viewing changes per-commit should tell that story pretty cleanly!

Extend api_post() to accept form data, files, and header overrides, and
make its arguments keyword-only. create_bitstream() now uses api_post()
instead of a hand-built prepared request, so uploads share the default
request headers and the reauthenticate/refresh_csrf decorators.

This also stops create_bitstream() from mutating session headers (which
may have leaked Content-Encoding: gzip into all subsequent requests),
drops the unused retry/reauthenticated parameters, and has download_bitstream()
merge into the default request headers rather than replace them.
Allow headers to be supplied at init that are included in every REST
API request, e.g. for environments where a proxy or gateway requires
an additional header. Mixins are applied last to the auth, default,
and uri-list request headers, so they take precedence over defaults.

For parity with api_post(), api_get() now merges any per-call headers
over the default request headers rather than replacing them, so mixins are
never dropped. download_bitstream() now passes only its Authorization
override.
@jonavellecuerdo jonavellecuerdo self-assigned this Oct 1, 2026

@ehanson8 ehanson8 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good!

is nice too and can always be parsed from this response later.
"""
r = self.api_post(url, parse_params(params, embeds), data)
r = self.api_post(url, params=parse_params(params, embeds), json=data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Appreciate the addition of named args here!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, I thought so too! I much prefer named over positional when it gets even remotely complex, or the arg values look similar.

Comment thread README.md
Comment on lines +49 to +58
### Custom request headers

Some environments require an additional header on every request (e.g. for a proxy or gateway). Pass these as
`request_header_mixins` when creating the client, and they will be included in all REST API requests, taking
precedence over the default headers:

```python
d = DSpaceClient(request_header_mixins={"X-Foo": "bar"})
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great context!

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.

3 participants