Skip to content

fix(api): support custom headers in pup api - #749

Merged
jack-edmonds-dd merged 2 commits into
DataDog:mainfrom
andyjmorgan:fix/api-header-override
Aug 21, 2026
Merged

fix(api): support custom headers in pup api#749
jack-edmonds-dd merged 2 commits into
DataDog:mainfrom
andyjmorgan:fix/api-header-override

Conversation

@andyjmorgan

Copy link
Copy Markdown
Contributor

Summary

We wish to add enhanced markdown functionality to the notebook tooling. To do so we need pup api to support custom headers, which today are silently ignored for Accept and Content-Type:

pup api -H "Accept: text/markdown" /api/<some-endpoint>     # returns JSON
pup api -X POST -H "Content-Type: text/markdown" ...        # 415 Unsupported Media Type

reqwest's header() appends rather than replaces, and pup set its JSON defaults before applying -H, so both values rode the request.

Changes

  • Parse -H before applying defaults; skip each default when the caller supplied that header (case-insensitive).
  • User-Agent stays non-overridable — audit logs attribute writes by it.

Testing

  • Covers Accept and Content-Type overrides, mixed-case header names, and defaults still applying when no -H is passed.
  • Verified against the live API: Accept: text/markdown returns text/markdown; charset=utf-8; Content-Type: text/markdown returns 201, previously 415.

Known gaps

  • Duplicate -H for the same header sends both values — expected for a raw passthrough.
  • Only Accept and Content-Type had hardcoded defaults, so only those are affected.

@andyjmorgan
andyjmorgan requested a review from a team as a code owner August 20, 2026 09:40
`pup api` advertises a repeatable -H flag, but Accept and Content-Type
were applied as JSON defaults before the user's headers. reqwest's
`header()` appends rather than replaces, so both values rode the request
and the server negotiated against the wrong one, leaving `pup api`
unable to reach any endpoint that does not speak JSON.

- Parse -H before applying defaults; skip each default when the caller
  supplied that header, matched case-insensitively
- Leave User-Agent non-overridable, since audit logs attribute writes by it

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@andyjmorgan
andyjmorgan force-pushed the fix/api-header-override branch from 10d919d to 73af031 Compare August 20, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants