mirror of
https://github.com/lloeki/nanoserve.git
synced 2025-12-06 03:04:39 +01:00
Implement form-urlencoded support
Query and form return a Hash, folding duplicates with last-key-wins strategy. *_array methods provide the seldom-used duplicate-preserving counterparts. Keep query and form separate, but provide params, which handles both, with form having precedence over query.
This commit is contained in:
parent
66a2a20663
commit
8a5c956a24
2 changed files with 64 additions and 2 deletions
|
|
@ -106,8 +106,28 @@ module NanoServe
|
|||
@uri.path
|
||||
end
|
||||
|
||||
def query_array
|
||||
URI.decode_www_form(@uri.query || '')
|
||||
end
|
||||
|
||||
def form_array
|
||||
form? ? URI.decode_www_form(body) : []
|
||||
end
|
||||
|
||||
def query
|
||||
Hash[*query_array.flatten]
|
||||
end
|
||||
|
||||
def form
|
||||
Hash[*form_array.flatten]
|
||||
end
|
||||
|
||||
def params
|
||||
Hash[*@uri.query.split('&').map { |kv| kv.split('=') }.flatten]
|
||||
query.merge(form)
|
||||
end
|
||||
|
||||
def form?
|
||||
content_type == 'application/x-www-form-urlencoded'
|
||||
end
|
||||
|
||||
def body
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue