Conversation
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.
ehanson8
approved these changes
Oct 2, 2026
| 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) |
There was a problem hiding this comment.
Appreciate the addition of named args here!
Author
There was a problem hiding this comment.
Thanks, I thought so too! I much prefer named over positional when it gets even remotely complex, or the arg values look similar.
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"}) | ||
| ``` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
api_post()DSpaceClientinit that get applied to all API HTTP requestsViewing changes per-commit should tell that story pretty cleanly!