Skip to content

Add experimental native Go proxy support - #101464

Merged
timneutkens merged 30 commits into
canaryfrom
codex/proxy-go
Nov 16, 2026
Merged

timneutkens merged 30 commits into
canaryfrom
codex/proxy-go

Conversation

@timneutkens

@timneutkens timneutkens commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add proxy.go and src/proxy.go with a Proxy(http.ResponseWriter, *http.Request) handler. experimental.goRoutes: true enables both Go routes and proxies. This first version matches all paths and uses deployment defaults; file-local configuration follows in #101551. Turbopack compiles the handler into a native HTTP worker for next dev and next start, with continuation, rewrites, redirects, request-header overrides, cookies, body replay, and streaming responses.

Adapter builds emit a MIDDLEWARE output with runtime: 'go' and a PORT-based executable. Hosted rollout also requires Go middleware packaging in adapter-vercel #156 and proxy-only build preparation in @vercel/next.

Go directory snapshots now respect the filesystem's denied paths, allowing a project-root proxy to compile alongside excluded .next output directories.

Differences from JavaScript proxies

  • Empty request-header replacement: in Go, a non-nil empty ProxyOptions.Request.Headers (http.Header{}) removes every downstream request header, while a nil map preserves them. In JavaScript, NextResponse.next({ request: { headers: new Headers() } }) is a no-op and the incoming headers are kept. Go expresses the empty replacement with an internal override name (x-next-internal-go-empty-override) so the JavaScript behavior is unchanged; Flight headers are still preserved. How the Vercel platform handles that override name is not verified yet, since hosted Go proxies depend on the companion adapter and builder changes.

Verification

  • A second differential pass covered 218 production pairs, 20 reduced method/scenario groups, and five stream/error checks. Fixed missing body framing on the hop into Go routes after header overrides or client chunking, with method-by-method continuation/rewrite/follow-up-request coverage.

  • Differential routing fuzzing covered 340 paired Go/JavaScript cases. Reduced production comparisons now match after fixes for encoded relative URLs, streamed DELETE/OPTIONS bodies, and downstream Date preservation.

  • Confirmed JSON/form Pages API body parsing and 600 KiB body replay; documented the ordinary Response versus NextResponse cookie-helper distinction.

  • Production, development, and Cache Components HTTP coverage passed, including root/src layouts and interoperability with Go route handlers.

  • Executed the emitted adapter server without Next.js to verify its PORT-based HTTP contract.

  • cargo test -p turbopack-go --test live -- --test-threads=2 — 12 passed, including directory exclusion, invalidation, and cache regressions.

  • Native route discovery/transport coverage, TypeScript, ESLint, and formatting checks passed.

  • Live Vercel deployment has not been verified. Deploy CI is gated until the companion adapter and builder changes are released and selected by the harness; the released builder does not provision Go for proxy-only apps.

  • Shared-flag config coverage, native route/proxy production suites, proxy development mode, and Cache Components checks pass.

  • Isolated public-type consumers and server trace snapshots pass. Go data-request URLs are covered with URL normalization enabled and disabled.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: e6ba212
View workflow run

Comment thread packages/next/src/server/next-server.ts Resolved
Comment thread crates/next-api/src/app.rs Resolved
Comment thread crates/next-api/src/app.rs Resolved
Comment thread crates/next-api/src/app.rs Resolved
@timneutkens
timneutkens marked this pull request as ready for review November 11, 2026 14:50
@timneutkens
timneutkens marked this pull request as draft November 11, 2026 14:50
@github-actions github-actions Bot added the Documentation Related to Next.js' official documentation. label Nov 11, 2026
Comment thread packages/next/src/server/config.ts Resolved
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Agent finished reviewing your changes.
721b1e7 • Sun, 15 Nov 2026 18:49:02 GMT

Vercel Agent's latest review does not approve this pull request under the repository's review policy.

Resolved issues (2)

packages/next/src/server/web/adapter.ts:234-246 — With skipProxyUrlNormalize: true and i18n configured, Go proxies still receive /protected instead of an incoming default-locale path such as /en/protected.
packages/next/src/server/lib/router-utils/resolve-routes.ts:702-704 — Empty request-header overrides still delete protected Flight headers because the adapter skips restoring them when x-middleware-override-headers is an empty string, breaking App Router navigation requests.

Review steps (1m 6s)

Preparing the workspace 34.3s
Analyzing the changes 24.6s
Finalizing the review 6.8s

timneutkens and others added 8 commits November 14, 2026 19:49
…as before. Go proxies express an empty header replacement with an internal override name instead, so their semantics and Flight header preservation are unchanged.

Only detect proxy.go when experimental.goRoutes is enabled, and only fail on multiple Proxy files when one of them is proxy.go. Multiple JavaScript Proxy files keep resolving as before.

Combine Go request-header values whose names differ only in case, and use the first X-Forwarded-Proto entry when resolving relative destinations.

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
timneutkens added a commit that referenced this pull request Nov 15, 2026
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
@timneutkens
timneutkens merged commit 0a520df into canary Nov 16, 2026
126 of 127 checks passed
@timneutkens
timneutkens deleted the codex/proxy-go branch November 16, 2026 13:22
jamiboym added a commit that referenced this pull request Nov 16, 2026
Resolve conflicts with #101464 (experimental native Go proxy). Canary's dev router now needs a runtime for the proxy (edge, nodejs or go) and gets it from the route watcher, which this branch no longer runs in Turbopack dev. Turbopack dev now sets it in handleEntrypoints:
- a native written endpoint means a proxy.go, with canary's middleware.native.json entry;
- otherwise the Edge middleware manifest decides between edge and nodejs, because Turbopack reports every JavaScript middleware endpoint as Edge.

The watcher's "Multiple Proxy files detected" check moves into the Turbopack root-file diagnostics: with experimental.goRoutes, proxy.go and src/proxy.go are candidates, in native middleware_files order, and a Go proxy next to another Proxy file is reported. Go files skip the JavaScript config validation.

The hot reloader conflict needed no change: this branch already skips /proxy and /src/proxy.
&serde_json::to_string(&route_pattern)?,
);
let handler = if is_proxy {
include_str!("templates/go_proxy_handler.go").to_owned()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a bit unexpected that this is a "template" since there is nothing to replace here, but seems fine...

Comment on lines 43 to 45
if (isAppDir && normalizedPagePath.endsWith('/route')) {
pagePaths.push(normalizedPagePath.slice(1) + '.go')
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does route.go doesn't require experimental.goRoutes?

folder: string,
extensions: string[]
extensions: string[],
goRoutes = false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These optional arguments are very easy to forget...

timneutkens added a commit that referenced this pull request Nov 16, 2026
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Turbopack team PRs by the Turbopack team. Documentation Related to Next.js' official documentation. tests Turbopack Related to Turbopack with Next.js. type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants