cgi.rb params initialize_query()

D

Dan Janowski

I assert that initialize_query is broken. CGI::parse should _always_ be
called on the QUERY_STRING, no matter if the REQUEST_METHOD is POST or
GET.

I would also say that instead of @params being an Array of Strings, it
should contain String like object that have an additional property that
indicates the parameter source, i.e. GET, POST, or COOKIE. Cookies
should also be in the @params so they can be [] found.

The only other point on this would be to allow optional order of
parsing, and thus the @params component array orders.

This is a staple of web programming and is something PHP does right and
JSP does wrong.

I think this can all be done in the dist cgi.rb without causing anyone
headaches.

Can these changes be incorporated into the next 1.8 with my help?

Dan
 
A

Aredridel

I assert that initialize_query is broken. CGI::parse should _always_ be
called on the QUERY_STRING, no matter if the REQUEST_METHOD is POST or
GET.

Biggest problem: one would overwrite the other, unless your string-like
objects were used as keys and hashed differently depending on origin.

Better to have separate arrays for get and post... ala modern PHP.

Ari
 
D

Dan Janowski

cgi params are always an array of values for a given key. A variety of
accessors are both possible and practical. Allow me to explain:

cgi['param'] returns the last value for param among get post and cookie
(the 1.8 behavior is first instance, I think it should be last
instance. This allows a form posted value to be easily used to override
a query string value. Good since forms are typically used to get input
from the client)

cgi.params('param') an array of all values

cgi.cookies('param') returning only cookies (not an array for param)

cgi.params_get('param') an array of only gets

cgi.params_post('param') an array of only posts

params_get('param') is really just: @params.collect {|po| po if
po.is_a? Get }.compact

get and post vals should be Get < String and Post < String.

This way a value gotten from cgi['param'] can be detected as post or
get or cookie.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Can't inherit CGI from cgi.rb 1
how do i configure this code 0
Trivial trick for looking at complex code 8
[ANN] clogger 0.0.1 0
ANN main-4.4.0 0
[ANN] main-0.0.2 5
[ANN] main-4.0.0 (for avdi) 0
[ANN] main-3.0.1 0

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top