Repository navigation
feat(rack): bind remaining Rack::Utils (secure_compare/clean_path_info/valid_path?/select_best_encoding/forwarded_values) - #126
Merged
Conversation
…o/valid_path?/select_best_encoding/forwarded_values) Bind the five Rack::Utils methods PR #125 skipped. They are exported by github.com/go-ruby-rack/rack's utils.go (SecureCompare, CleanPathInfo, ValidPath, SelectBestEncoding, ForwardedValues); bump the rack pin so they resolve, then dispatch through the existing value-mapping helpers: - secure_compare(a, b) -> SecureCompare (constant-time bool) - clean_path_info(path) -> CleanPathInfo (traversal-safe) - valid_path?(path) -> ValidPath (bool) - select_best_encoding(avail, acc) -> SelectBestEncoding (MRI arg order: available list first, pre-parsed [name, quality] accept list second; nil when nothing acceptable) - forwarded_values(header) -> ForwardedValues (RFC 7239; symbol keys in header order, nil on a falsy/disallowed header) ForwardedValues returns an unordered map[string][]string, so the binding reconstructs MRI's header-appearance key order with rackForwardedOrder (mirrors the Go tokeniser, names only) before materialising the symbol-keyed Hash. New helpers rackFloat / rackQValues / rackForwardedArg carry the value mapping. Verified byte-identical to MRI 4.0.5 + rack 3.2.6 through the rbgo binary for all five (including reordered / quoted / IPv6 / duplicate-key / empty-header Forwarded cases). 100% coverage on rack.go and rack_helpers.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #125 bound most of
Rack::Utilsbut skipped five methods on the premise thatgo-ruby-rack/rackdid not export them. That was a stale-pin artifact:rack'sutils.goonmainexports all five as Go funcs. This PR bumps therackpin so they resolve and binds them, dispatching through the existing value-mapping helpers.secure_compare(a, b)SecureCompareclean_path_info(path)CleanPathInfovalid_path?(path)ValidPathselect_best_encoding(available, accept_encoding)SelectBestEncoding[name, quality]accept list second;nilwhen nothing acceptableforwarded_values(header)ForwardedValuesnilon a falsy/disallowed headerforwarded_valuesorderingForwardedValuesreturns an unorderedmap[string][]string, which alone cannot reproduce MRI's header-appearance key order. The binding reconstructs that order withrackForwardedOrder(mirrors the Go tokeniser, names only) before building the symbol-keyed Hash, so the output is byte-identical to MRI ({for: [...], proto: [...]}).Verification
Byte-for-byte diff of a snippet exercising all five, run through the
rbgobinary vs MRI 4.0.5 + rack 3.2.6 — identical, including reordered / quoted / IPv6 / duplicate-key / empty-header Forwarded cases and theselect_best_encoding*/identity/tie/nilarms.select_best_encodingarg order confirmed against real rack 3.2.6:select_best_encoding(%w[gzip identity], [["gzip",1.0],["identity",0.5]]) #=> "gzip".Empty/no-param Forwarded headers return
{}(notnil) in rack 3.2.6, and the Go func matches — verified against MRI.GOWORK=off go build ./... && go vet ./... && go test ./...greenrack.goandrack_helpers.go🤖 Generated with Claude Code