[Catalyst-dev] Separate access to query string and body parameters

Dan Kubb dan.kubb at autopilotmarketing.com
Fri Aug 5 10:55:47 CEST 2005


Marcus said I should post a message to the dev list about a possible
patch to Catalyst::Request (and the engines) that would add the ability
for you to access the query string parameters separately from any
parameters passed in with a POST request.

In addition to this I'd like to propose a second method that allows
access to the request body parameters separately.

The reason for this is to keep the meaning between the two pieces
of information separate.  One is part of the URI -- the unique
identifier of a resource on the web -- and the other is metadata
for a request operation performed on a resource.

The query string parameters and the body parameters are so completely
different, they were never intended to be used interchangeably.  When
they are, unintended things can happen.  Like when Google's Web  
Accelerator
assumed that it could fetch any URL with a GET and not have any
side effects.  According to the RFC's their assumption was correct, but
they soon found out that a lot of web developers were using HTTP in
ways they aren't suppose to (like having deletion commands accessible
via a GET request).

Many frameworks don't make it easy enough to do the right thing and
some even encourage "broken" usage of HTTP.  I'd like to make sure that
Catalyst doesn't prevent people from doing things according to the
RFCs should they wish to, while not placing any unnecessary burden on
developers who don't care either way.

Anyway.. thats my reasoning.  Here's what I want to do:

I'd like to add two methods to C::Request called query and body
that work like this:

   # query()  -- for the query string

   my @fields = $req->query;
   my $value  = $req->query($field);
   my @values = $req->query($field);

   $req->query($field => $value);
   $req->query($field => @values);


   # body()   -- for the body data

   my @fields = $req->body;
   my $value  = $req->body($field);
   my @values = $req->body($field);

   $req->body($field => $value);
   $req->body($field => @values);

The param method will obviously need to continue to work, but it
could be made into a wrapper around the query and body methods
if you didn't want to have any duplication of data under the hood.
Otherwise I could just leave it alone -- although I'd vote for
wrapping.

For more uniformity with the existing API, a query_string and
body_data method could be added.  They could just return hashrefs to
the underlying data, similar to how parameters and uploads work.

So what do you think?  Are there any reasons you can think of that
this would be a bad idea?

Thanks,

Dan



More information about the Catalyst-dev mailing list