Skip to content

HttpApiSchema.Upgrade: allow a regular success for servers that don't upgrade #9912

Closed

Description

@fubhy

Problem

A server may answer a request that asks for an upgrade without switching protocols. HTTP allows it (RFC 9110 §7.8: "A server MAY ignore a received Upgrade header field"), and some APIs rely on it:

  • Docker's POST /exec/{id}/start answers 101 with the exec's stdio when attached, and 200 with no body when the request says "Detach": true.
  • An h2c upgrade (Upgrade: h2c) is answered by HTTP/1.1 when the server doesn't speak HTTP/2 in cleartext.

An upgrade endpoint can't declare another success (HttpApiEndpoint.ts L1377):

HttpApiEndpoint.post("start", "/exec/:id/start", {
  params: { id: Schema.String },
  payload: ExecStartConfig,
  success: [HttpApiSchema.Upgrade({ protocol: "tcp" }), HttpApiSchema.Empty(200)]
})
// Error: Cannot combine an upgrade with other success responses

So a declaration has to restrict its requests to the upgrading ones (Docker's client allows only Detach: false), or leave the endpoint out.

Proposal

Allow one Upgrade together with buffered or no-content successes at other statuses.

  • Client: the method returns the upgrade or the other success. The upgrade is a tagged value, so callers can tell the two apart:

    const result = yield* client.exec.start({ params: { id }, payload })
    if (HttpApiClient.isUpgraded(result)) {
      const reader = yield* result.socket.reader
    } else {
      // detached: the 200's decoded value
    }

    Endpoints with only an Upgrade keep returning { headers, socket }.

  • Server: the handler calls upgrade() to switch protocols, or returns a value of one of the other successes without calling it.

  • OpenAPI: the 101 and the other statuses are listed side by side.

Scope

In scope: one Upgrade and buffered or no-content successes.

Out of scope: streaming successes next to an upgrade, and WebSocket.

Cost

  • The client's result type for such endpoints becomes a union with a tagged upgrade, and a handler either calls upgrade() or returns a value. Both shapes get more complex for a rare case.
  • OpenAPI already describes it (two statuses of one operation), so all the work is in the client and handler types. Without this, a declaration restricts requests to the upgrading ones, as Docker's client does with Detach: false.

Open questions

  • Should the upgraded value always be tagged (a breaking change for the result type), or only when another success is declared?

Activity

  1. added
    enhancement
    docker-made-me-do-it
    on Oct 25, 2026
  2. self-assigned this
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docker-made-me-do-itenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions