[PATCH] Parsing non-nested requests
Reported by bahuvrihi | August 11th, 2009 @ 02:56 PM | in 1.1
I have run into situations where I'd like to parse requests in a
non-nested fashion. Rack::Request almost lets you do this, but not
quite. This commit refactors Rack::Request so that the parsing
methods for query strings and multipart data may be
overridden.
http://github.com/bahuvrihi/rack/commit/fa29dc523a0994a85686b01a192...
Query Strings
With the patch, you can parse non-nested query strings by subclassing Request to call Utils.parse_query instead of Utils.parse_nested_query.
Multipart Data
Parsing multipart data in a non-nested fashion requires second patch because parse_multipart parses nested queries and you can't get around that. This commit adds a flag to parse_multipart to allow non-nested parsing.
http://github.com/bahuvrihi/rack/commit/d6a2a162651c8068822a9370fe6...
The flag is a little inelegant, but at least it's backwards compatible. A more elegant solution would be to have two methods: parse_multipart and parse_nested_multipart. However, this solution is problematic because it requires surprising, backwards-incompatible flip in the meaning of parse_multipart.
With both patches a non-multipart request class looks like this:
class NonMultipartRequest < Request
def parse_query(qs)
Utils.parse_query(qs)
end
def parse_multipart(env)
Utils::Multipart.parse_multipart(env, false)
end
end
Comments and changes to this ticket
-
josh December 11th, 2009 @ 03:13 AM
- Assigned user set to josh
- State changed from new to open
- Milestone set to 1.1
I'd go with parse_multipart and parse_nested_multipart since this will be merged into 1.1.
-
josh December 21st, 2009 @ 02:53 AM
- State changed from open to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป