feat(std/http): upgrade a connection with 101 Switching Protocols and a Duplex #458
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/74-http-upgrade-duplex"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #74
Server side of NETWORK.md slice 14 as amended in the decision comment on #74:
Status.switchingProtocols,Response.upgrade(handler, headers),UpgradeandDuplex(source, sink, remote, isEncrypted) instd/http.serveConnectionwrites the101with the handler's own fields and no framing, hands the closure the connection (buffered bytes first), keeps itbusysoshutdown(grace)waits and then cancels, and never reads it as HTTP again. A101without a closure, or a closure with another status, is answered500. WebSocket framing stays withstd/web(#105).Tests:
tests/conformance/http-upgrade.trb(cases 1 to 7) andhttps-upgrade.trb(a copy of thehttps-exchangefixture, cases 1 to 4). Written without a local compiler (builds run in CI only), so the.expectedfiles are predicted and may need a CI round.Status: draft until forge CI is green; the docs commit (http.md, NETWORK.md, skills/) follows.
CI: pending
101 Switching Protocolsand a duplex connection (NETWORK slice 14) #74101 Switching Protocolsand a duplex connection (NETWORK slice 14) #74Checklist on
5316ae6:http-upgrade(cases 1-7) andhttps-upgrade(cases 1-4) cover the head bytes, early bytes, both directions, half-close either way, a plain request beside an open upgrade, a bare101answered 500, and shutdown grace then cancel. CI is green on this head (bootstrap, tier A, tier B, gates, pdisc).101/takeover mismatch check is symmetric (a bare101and a takeover with another status both become 500, takeover dropped). The peer watcher is cancelled and joined before the upgrade, so no read races the closure and buffered bytes stay in the connection forDuplex.source(). An undrained body closes instead of upgrading.writeUpgradekeeps the handler'sConnection: Upgradeand still drops length/coding and sanitizes names and values. The connection staysbusy, so shutdown waits and then cancels.std/web.Duplex,Upgrade,Response.upgrade,Status.switchingProtocols), documented in NETWORK.md.Non-blocking:
writeUpgradealways writesHTTP/1.1, also for an HTTP/1.0 request. Harmless, since 101 needs 1.1 anyway; a one-line note in the docs would settle it.