mjackson / mjackson/rack-accept

Accessing request params via Rack::Accept::Request

Open
#10 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
48
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Rack::Accept::Request overrides media_type but changes the return value. Instead of returning the request's content-type -less charset, like its parent, it returns an accept header (as an instance of MediaType). This prevents one from retrieving POST params:

[Rack::Accept::Request, Rack::Request].each do |klass|
  env = {    
    "rack.input"     => StringIO.new("a=b+c"), 
    "CONTENT_TYPE"   => "multipart/form-data",
    "REQUEST_METHOD" => "POST"
  }

  r = klass.new(env)  
  puts "#{klass.name}#POST: #{r.POST}"
  puts "#{klass.name}#media_type: #{r.media_type}"   
  puts "*" * 10
end

Prints:

Rack::Accept::Request#POST: {}
Rack::Accept::Request#media_type: Accept: 
**********
Rack::Request#POST: {"a"=>"b c"}
Rack::Request#media_type: multipart/form-data
**********

Maybe it's better to call the method accept

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Rack::Accept::Request#media_type and compare it with Rack::Request#media_type, using the reproduction in the issue to confirm how the override affects POST parsing. Add regression coverage for request parameters and verify that media type and Accept handling produce the intended values.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.