Fork me on GitHub
Digital Commons

go-ruby-rack

Ruby's Rack โ€” the SPEC value types and the pure-compute core of the rack gem โ€” in Go, .

Ruby Rack 3.xenv & SPEC tuplequery ยท nested paramsescape ยท cookiesstatus codes ยท headersRequest ยท ResponseMRI byte-exact100% coverage6 arches ยท 3 OSes
Documentation (MkDocs Material + mike) Go 1.26.4+ Coverage 100%
zsh
$ go get github.com/go-ruby-rack/rack@latest

go-ruby-rack is a pure-Go (no cgo) reimplementation of the deterministic core of Ruby's Rack โ€” the SPEC value types and the pure-compute utilities of Rack::Utils, Rack::Request, Rack::Response, Rack::MediaType and the header machinery โ€” matching the MRI rack gem (Rack 3.x) byte-for-byte. It shapes a Rack environment, parses and builds query strings and cookies, escapes and unescapes URI/HTML, maps HTTP status codes, and produces the [status, headers, body] SPEC tuple โ€” without any Ruby runtime. The HTTP server โ€” the socket accept loop, TLS, Rack::Handler โ€” is the host's job and stays out of scope; reading the body is one explicit Input seam. It is a standalone, reusable module โ€” the Rack backend bound into go-embedded-ruby by rbgo, a sibling of go-ruby-regexp, go-ruby-erb and go-ruby-yaml โ€” differential-tested against the rack gem, 100% coverage, CI green across 6 arches and 3 OSes.

Query & parameters ready

ParseQuery / ParseNestedQuery expand foo[bar] / foo[] / x[][a] bracket nesting exactly like the gem โ€” array-of-hash vs nested-array subtleties, ParameterTypeError / ParamsTooDeepError conflicts and all โ€” and BuildQuery / BuildNestedQuery invert them.

Escaping ready

Escape / Unescape (encode/decode_www_form_component, space โ†” +), EscapePath / UnescapePath (RFC 2396) and EscapeHTML / UnescapeHTML โ€” byte-identical to MRI down to the unreserved set and upper-case hex.

Status codes & headers ready

The full HTTPStatusCodes table, the symbol โ†’ code reverse map (deprecated aliases included), StatusWithNoEntityBody, and Headers โ€” the insertion-ordered, key-down-casing map mirroring Rack::Headers.

Request over an Env ready

Method predicates, PathInfo / QueryString / GET / POST / Params / Cookies, ContentType / MediaType, Host / Port / Scheme / SSL / BaseURL / URL / Fullpath, XHR, and IP with the trusted-proxy filter.

Response & the SPEC tuple ready

NewResponse(body, status, headers), Write, Finish / ToA (the [status, headers, body] tuple), SetStatus, header get/set, SetCookie / DeleteCookie, Redirect, and the status-class predicates.

Negotiation, cookies & the body seam ready

QValues, BestQMatch, GetByteRanges; ParseCookiesHeader, MakeCookieHeader / MakeDeleteCookieHeader; and the single Input seam through which the host supplies the request body โ€” so the package never touches the network.

Differential oracle & coverage ready

Every escaping, query-parse, status, cookie, media-type, byte-range and Response#finish case is checked byte-for-byte against the system ruby with the rack gem; 100% coverage, gofmt + go vet clean, green across 6 arches and 3 OSes.

A faithful pure-Go port of Rack's pure-compute surface, cgo disabled, so it cross-compiles and embeds anywhere. Validated differentially against the system ruby with the rack gem, byte-for-byte. It is a standalone, reusable module extracted from rbgo's internals, and the backend bound by rbgo into the sibling org github.com/go-embedded-ruby.