Good day, all. I currently have some code that use HTTP::Daemon and CGI.pm in one script: the HTTP::Daemon portion listens for requests, and sends relevant GET or POST information off to CGI.pm, where it's used throughout the whole program, non-OOP. The shell is something like this:
my $connection = $daemon->accept; my $request = $connection->get_request; next unless defined $request;
my $form_parameters;
if ( $request->uri =~ /\?/ ) { $form_parameters = $request->uri; $form_parameters =~ s/[^\?]+\?(.*)/$1/; } else { $form_parameters = $request->content; } $CGI::Q = new CGI($form_parameters);
This seemed to work fine, giving me the ability to access POST and GETs via params() in my templates or other bits of code. However, I now have a need to use a multipart/form-data with a file upload. The crux of this email is: it doesn't work. No parameters seem to be found - almost acting as if a POST was never sent in the first place. The minute I take away the multipart/form-data, everything works again.
I *believe* this is due to the following lines of CGI.pm:
if ($meth eq 'POST' && defined($ENV{'CONTENT_TYPE'}) && $ENV{'CONTENT_TYPE'}=~m|^multipart/form-data| && !defined($initializer) ) { my($boundary) = $ENV{'CONTENT_TYPE'} =~ /boundary=\"?([^\";,]+)\"?/; $self->read_multipart($boundary,$content_length); last METHOD; }
specifically, the CONTENT_TYPE. In testing with Apache, no CONTENT_TYPE is defined during normal POST or GET operations, but the minute Mozilla sends Apache a multipart/form-data, one springs into existence (one line):
'multipart/form-data; boundary=---------------------------11323553721538',
Since I haven't explicitly told my HTTP::Daemon code (above) to create a CONTENT_TYPE variable, CGI.pm doesn't create the multipart parameters as it should (this, of course, is only my interpretation).
This seems to be the case when I issue a Data::Dumper on Vars (snip), and I see the boundary data as part of the output. The boundary data should never have been there (since it would have been processed via the regexp and read_multipart from the above CGI.pm snippet):
VAR1 = { '-----------------------------34303110730191 Content-Disposition: form-data' => '', ' name' => '"Submitter" ----------------------------- 34303110730191 Content-Disposition: form-data
etc. etc.
So, I've one question, really: how do I accurately create CONTENT_TYPE for CGI.pm's use? If I $request->content, I'll get the POST data, with the boundary data for each parameter submitted, but due to idiocy, I've yet to properly yank out that data, combine it with ->content_type, and set ENV:
my $boundary = $request->content; <!-- ENTER MAGICK HERE --> my $final = $request->content_type . "; boundary=$boundary"; $ENV{'CONTENT_TYPE'} = $final;
Is there a proper way to do this? Is this even the correct solution to my problem (multiparts don't work)? A cursory glance into some of the MIME modules didn't show an immediately obvious ->boundary getter.
Thanks for any thoughts or comments.
-- Morbus Iff ( i put the demon back in codemonkey ) Culture: http://www.disobey.com/ and http://www.gamegrene.com/ Spidering Hacks: http://amazon.com/exec/obidos/ASIN/0596005776/disobeycom icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus