Skip to content

[4.x] Send GitHub API headers per request and update to the current API conventions - #65

Open
Hackwar wants to merge 6 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-github-update
Open

Hackwar wants to merge 6 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-github-update

Conversation

@Hackwar

@Hackwar Hackwar commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

Aligns the HTTP layer with GitHub's current REST API conventions and fixes how credentials are sent.

  • Headers are sent per request, not stored on the HTTP client. Before, fetchUrl() wrote Authorization: token … into the client's headers option, and only if it was not set yet. A changed gh.token was never used, and every later request through the same (possibly shared, e.g. DI) client carried the GitHub token, including requests to other hosts. When the client was built from the options Registry, the header also ended up in the user's Registry. The package objects now wrap the client (Joomla\Github\RequestHeadersHttp, internal) so that the headers are computed from the options on each request and put on the client only for the duration of that request. Headers set on the client or passed with a request keep precedence. This keeps every existing call site, and those of the new packages in [4.x] Register the new API packages #67–[4.x] Add the Dependency Graph API package  #85, working unchanged.
  • Every request sends Accept: application/vnd.github+json and X-GitHub-Api-Version (option api.version, default 2022-11-28).
  • JSON request bodies are sent with Content-Type: application/json instead of the transport default application/x-www-form-urlencoded (only for string bodies, and only when no content type is set on the client or passed with the request).
  • New option gh.token_scheme (default token), e.g. Bearer for GitHub App tokens. (An earlier commit called it gh.token.scheme, but a Registry cannot hold gh.token and gh.token.scheme at the same time — setting one makes the other unreachable.)
  • Basic auth (api.username/api.password) is sent as an Authorization: Basic header instead of unencoded URL userinfo (a password like p@ss:w/rd sent the request to the wrong host and leaked into exception messages). It only works on GitHub Enterprise Server.
  • api.url defaults to https://api.github.com in fetchUrl(), so a package constructed without Github no longer requests a relative URL.
  • Deprecations: only the dead methods of Authorization are deprecated (getRateLimit(), getAuthorizationLink() and requestToken() still work), and Repositories\Downloads. All trigger a runtime deprecation (adds symfony/deprecation-contracts).

Testing Instructions

Tests/GithubObjectTest.php sends requests through a real Http with a recording transport: token rotation, no headers left on the client or in the options Registry, a second request through the shared client without the token, client headers taking precedence, api.version/gh.token_scheme, the JSON content type, Basic auth as header, sub-packages. These fail before the change. The package tests set api.url to '' in GitHubTestCase so they can keep asserting relative paths.

Documentation Changes Required

docs/overview.md: options and headers, deprecated endpoints. (The 4.1 notes are no longer in v3-to-v4-update.md; that guide is for breaking changes only.)
#66 needs adjusting when either is merged second: authentication.md documents gh.token.scheme (now gh.token_scheme), the Basic auth userinfo caveat and the "Isolating the HTTP client" section (no longer needed), and packages.md says the whole Authorization class is dead apart from getRateLimit().

🤖 Generated with Claude Code

@Hackwar
Hackwar changed the base branch from 3.x-dev to 4.x-dev July 26, 2026 17:28
@Hackwar Hackwar changed the title Switch Github Actions to v4 workflow Update to newer Github API Jul 26, 2026
Hackwar and others added 4 commits July 26, 2026 19:29
…ient

The Authorization header was written into the HTTP client's options and only
when it was not set yet. A rotated token was never used, and every later
request through a shared client carried the token, including requests to
other hosts. Basic auth credentials were put unencoded into the URL.

Wrap the client so that the headers (Accept, X-GitHub-Api-Version,
Authorization) are computed from the options on every request and put on
the client only for that request. Send Basic auth as an Authorization
header. Default api.url to api.github.com for packages built without
Github. Rename gh.token.scheme to gh.token_scheme, because a Registry
cannot hold gh.token and gh.token.scheme at the same time.

Deprecate only the dead methods of Authorization (getRateLimit(),
getAuthorizationLink() and requestToken() still work) and trigger runtime
deprecations for them and for Downloads. Document the options in
overview.md instead of the v3 to v4 update guide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar Hackwar changed the title Update to newer Github API [4.x] Send GitHub API headers per request and update to the current API conventions Nov 12, 2026
The packages send JSON strings as request bodies, but without a content
type joomla/http labels them application/x-www-form-urlencoded. Add
Content-Type: application/json for string bodies unless a content type
is set on the client or passed with the request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant