Skip to content

fix(upstream): let the runtime own Accept and Content-Length placement - #143

Merged
jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
AiFLYF:pr-c-wire
Oct 23, 2026
Merged

jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
AiFLYF:pr-c-wire

Conversation

@AiFLYF

@AiFLYF AiFLYF commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What

A captured 2.1.1 request has no Accept header and no trailing
Content-Length. Both come from fetch, which fills Accept with */* and
computes Content-Length as part of its common-header block.

The gateway set both itself, so the v2 lane sent:

Accept: application/json, text/event-stream     ← the client never produces this
...
Connection: keep-alive
Content-Length: 24293                           ← the client has it up top

Header presence and order are part of what a fingerprint sees, so both are now
left to the transport:

  • setV2Headers no longer sets Accept.
  • The Bun head emits Content-Length among the common headers, where fetch
    computes it, instead of trailing the request.

The v1 lane keeps its own Accept — that client does send one.

Why this is a separate PR

It changes only what the wire looks like, not what the body contains, so it can
be reviewed and reverted on its own.

How it was verified

  • Captured request dump: no Accept, Content-Length in the common block.
  • Rendered Bun head after the change: Content-Length sits with the other
    common headers and Accept: */* is emitted by the runtime.
  • Live against the real upstream, both lanes: 200 on chat, streaming, tool
    calls, /v1/messages and /v1/responses.
  • go build ./..., go vet ./..., gofmt clean.

A captured 2.1.1 request carries neither an Accept header nor a trailing
Content-Length: fetch fills Accept with */* and computes Content-Length as
part of the common-header block. The gateway set both itself, so the v2 lane
sent an Accept value the client never produces and put Content-Length last,
where no fetch request has it.

Header order and presence are part of what a fingerprint sees, so the v2 lane
now sets no Accept and the Bun head emits Content-Length among the common
headers instead of trailing the request.

The v1 lane keeps its own Accept, which is what that client sends.
@jasonxu114514
jasonxu114514 merged commit 4e2edbf into jasonxu114514:main Oct 23, 2026
5 checks passed
TiaraBasori added a commit to TiaraBasori/opencode2api-1 that referenced this pull request Oct 25, 2026
…breaker)

Pick up origin/main (19 commits since v1.4.3):

- 2.1.1 client shape: version bump, /inference/openai|anthropic family
  routes, max_completion_tokens 32000, strict:false tools, client key
  order, no HTML escaping, runtime-owned Accept/Content-Length (jasonxu114514#141-jasonxu114514#143)
- anonymous-lane abuse handling: IP-block detection, per-exit block TTL,
  circuit breaker (models.anonymous_backoff), max_anonymous_exits cap,
  deterministic 4xx stops the walk instead of replaying every exit
- placeholder key dropping, probe failure classification (jasonxu114514#111),
  WebUI Cache-Control (jasonxu114514#112), reasoning disable preserved end to end
  (jasonxu114514#150), Italian README/WebUI

Conflict resolutions:
- internal/config/config.go, README.md, README.zh-CN.md: kept both sides —
  the alias fields (aliases/strip_free_suffix) and the new
  anonymous_backoff block sit side by side in ModelsConfig and the README
  tables.

Local adaptation for this deployment's #pool exit (not upstream):
- a #pool transport dials a fresh upstream address on every attempt, so an
  IP-scoped abuse block cannot be parked on the transport: blocked() and
  markBlocked() ignore pool transports and the anonymous walk keeps
  rotating instead of freezing every exit behind one flagged address.
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.

2 participants