GeezerVison is showing github.com — Plugin http.request hook: redirect mode on the returned Request is dropped, so redirects are always followed · Issue #61272 · anomalyco/opencode
Plugin http.request hook: redirect mode on the returned Request is dropped, so redirects are always followed #61272DescriptionDescription
A plugin's http.request hook can return a replacement Request. OpenCode 2.2.0 keeps only its URL, method, headers and body when it converts it back for sending. Fields such as redirect are dropped. As a result, a hook that sets redirect: 'manual' still has every 301/302/303/307/308 followed by the runtime's default fetch policy.
This matters for plugins that place a credential on the request. Bun strips Authorization on a cross-origin redirect, but it can't strip a credential that the redirect's Location carries in its path or query. A plugin that wants to inspect or refuse a redirect before it's followed has no way to do so: http.response runs only after the redirect chain finishes, and model.request exposes only the base URL and headers.
Where it happens (v2.2.0)
packages/core/src/session/model-request.ts:323-340: the hook's returned Request is converted with HttpClientRequest.fromWeb(...) and passed to the handler.
[email protected] src/http/HttpClientRequest.ts:1384-1391 (fromWeb): copies method, URL, headers and body only; request.redirect is not read.
[email protected] src/http/FetchHttpClient.ts:56-76: calls fetch(url, { ...options, method, headers, body, duplex, signal }) with the context RequestInit, which the host sets to { timeout: false } (packages/core/src/effect/app-node-platform.ts), so no redirect mode reaches fetch.
- Bun 1.4.4
src/runtime/webcore/fetch.rs:460 defaults to FetchRedirect::Follow.
Steps to reproduce
- Configure an OpenAI-compatible provider whose base URL points at a local server.
- Install a plugin whose
http.request hook returns new Request(input.request, { redirect: 'manual' }).
- Have the local server answer the first request with
307 Location: http://127.0.0.1:<other-port>/somewhere.
- Send a prompt. The second server receives the request: the redirect was followed although the hook asked for
manual.
Expected
The hook-returned Request's redirect mode reaches the fetch call, so manual returns the 3xx to the http.response hook unfollowed and error fails it. Alternatively, a supported per-request or per-provider transport option for redirect handling.
OpenCode version
2.2.0 (@opencode/core 2.2.0, @opencode/ai 2.2.0), Bun 1.4.4.
Operating system
Reproduced on Linux; the code path is platform-independent. Activityopencodejr commented on Nov 2, 2026 Thanks for the detailed write-up and the code pointers.
To restate the request: when a plugin's http.request hook returns a Request with a redirect mode (manual or error), OpenCode should honour it. That way a plugin can inspect or refuse a 3xx before it's followed, for example to avoid sending a credential to a redirect target. Your reading of the code is correct: the returned Request currently keeps only its URL, method, headers and body, and redirect isn't part of what the hook supports today. So I've filed this as a feature request rather than a bug. Maintainers will consider it.
This can't be done as a plugin right now. http.request can't affect the fetch options, http.response only runs after the redirect chain has finished, and model.request only exposes the base URL and headers. Possible API additions for maintainers to consider:
- carry the
redirect mode (and possibly other RequestInit fields) of the hook's returned Request through to the actual fetch call, or
- add an explicit
redirect: "follow" | "manual" | "error" option to the http.request hook, or as a per-provider transport setting, with manual handing the 3xx response to http.response.
I didn't find an existing issue asking for this. #59748 applies URL rules to redirect targets in the webfetch tool, so it's only loosely related.
argszero commented on Nov 3, 2026 I'd like to work on this.
I reproduced it on this machine before claiming. HttpClientRequest.fromWeb keeps only method, url, urlParams, hash, headers and body, so a hook-returned Request with redirect: "manual" comes out of packages/core/src/session/model-request.ts with no redirect mode at all, and toWeb brings it back as undefined:
web Request.redirect : manual
fromWeb record keys : method,url,urlParams,hash,headers,body
after fromWeb : undefined
round-trip via toWeb : undefined
End to end, with a source server answering 307 Location: at a second server, the second server receives the request (final status 200, target reached: YES), so the manual request is followed anyway.
Plan: carry the hook-returned Request's redirect mode across the conversion in model-request.ts so manual / error reach the fetch call as the hook asked, leaving follow as the default when a hook does not set it. I'll add a regression test covering manual and error, and run the adjacent session/plugin tests plus typecheck before opening a PR.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|