Re: Redirecting a multipart/form-data POST request

2001-01-24 Thread Doug MacEachern

On Tue, 16 Jan 2001, Darren Stuart Embry wrote:

 On 2001-01-15, Ask Bjoern Hansen [EMAIL PROTECTED] wrote:
 
   When I do neither, i.e., leave the POST request as is and use
   the standard redirect mechanism, the browser hangs and the
   server actually does not send the redirect until I hit the Stop
   button (I'm using ngrep to determine this).  This also happens
   if I use the $r-print($header) method and still return
   REDIRECT.
 
  Try adding 
  
  $r-method('GET');
  $r-headers_in-unset('Content-length');
  
  to your code before doing the return REDIRECT.
 
 Ask Bjoern, I privately replied to you on this as well.
 
 I should have been more clear and said I was doing exactly this,
 as per [1], when I mentioned I was converting POST requests to
 GET requests.
 
 This is so that I could get redirects to work in response to a
 urlencoded POST request using the standard redirection technique
 of setting the Location header and mime type and returning
 REDIRECT instead of manually constructing and $r-print()ing a
 header.
 
 In any case, [1] does me no good with multipart/form-data which
 is what I was asking about in the first place.

you need 1.24_01 which contains this fix:
fix $r-read() so it will not block if all data has already been read
and so that Apache will not hang during ap_discard_request_body() on
error or redirect after all data has been read





Re: Redirecting a multipart/form-data POST request

2001-01-16 Thread Darren Stuart Embry

On 2001-01-15, Ask Bjoern Hansen [EMAIL PROTECTED] wrote:

  When I do neither, i.e., leave the POST request as is and use
  the standard redirect mechanism, the browser hangs and the
  server actually does not send the redirect until I hit the Stop
  button (I'm using ngrep to determine this).  This also happens
  if I use the $r-print($header) method and still return
  REDIRECT.

 Try adding 
 
 $r-method('GET');
 $r-headers_in-unset('Content-length');
 
 to your code before doing the return REDIRECT.

Ask Bjoern, I privately replied to you on this as well.

I should have been more clear and said I was doing exactly this,
as per [1], when I mentioned I was converting POST requests to
GET requests.

This is so that I could get redirects to work in response to a
urlencoded POST request using the standard redirection technique
of setting the Location header and mime type and returning
REDIRECT instead of manually constructing and $r-print()ing a
header.

In any case, [1] does me no good with multipart/form-data which
is what I was asking about in the first place.

Darren

[1] http://perl.apache.org/guide/snippets.html#Convert_a_POST_Request_into_a_GE

-- 
Darren Stuart Embry.  A whole roasted almond in every piece!
http://www.webonastick.com/
``To undo most things in Excel, click the undo button.''
  -- Actual ToolTip from Microsoft Office 97



Re: Redirecting a multipart/form-data POST request

2001-01-16 Thread Gerd Kortemeyer

 I am writing a program that needs to process form data, (here's
   the kicker) which is sometimes multipart/form-data, then
   redirect a user to a GET request (which doesn't need to process
   the form data).  I would like to use the standard mechanism for
   issuing a redirect, for other reasons:

   $r-header_out('Location' = $url);
   return REDIRECT;


Not sure what the problem is, but I frequently use REDIRECTs and receive both
"normal" and "multipart" posts.

Please find the code section below that I use to get the POSTed data. After
that, in order to REDIRECT, I use

  $r-content_type('text/html');
   $r-header_out(Location =
'http://'.$ENV{'HTTP_HOST'}.$disurl);
   return REDIRECT;

Hope this helps.

Enjoy,

- Gerd.

 Getting all kind of posted stuff:

my $buffer;

$r-read($buffer,$r-header_in('Content-length'));

unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si)
{
my @pairs=split(//,$buffer);
my $pair;
foreach $pair (@pairs) {
   my ($name,$value) = split(/=/,$pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
   $name  =~ tr/+/ /;
   $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
   $ENV{"form.$name"}=$value;
}
} else {
my $contentsep=$1;
my @lines = split (/\n/,$buffer);
my $name='';
my $value='';
my $fname='';
my $fmime='';
my $i;
for ($i=0;$i=$#lines;$i++) {
if ($lines[$i]=~/^$contentsep/) {
if ($name) {
chomp($value);
if ($fname) {
$ENV{"form.$name.filename"}=$fname;
$ENV{"form.$name.mimetype"}=$fmime;
} else {
$value=~s/\s+$//s;
}
$ENV{"form.$name"}=$value;
}
if ($i$#lines) {
$i++;
$lines[$i]=~

/Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
$name=$1;
$value='';
if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
   $fname=$1;
   if
($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {

  $fmime=$1;
  $i++;
   } else {
  $fmime='';
   }
} else {
$fname='';
$fmime='';
}
$i++;
}
} else {
$value.=$lines[$i]."\n";
}
}
}
$r-method_number(M_GET);
$r-method('GET');
$r-headers_in-unset('Content-length');






begin:vcard 
n:Kortemeyer;Gerd
tel;fax:(517) 432-2175
tel;work:(517) 432-5468
x-mozilla-html:FALSE
url:http://www.lite.msu.edu/kortemeyer/
org:LITE Lab;DSME MSU
version:2.1
email;internet:[EMAIL PROTECTED]
title:Instructional Technology Specialist
adr;quoted-printable:;;123 North Kedzie Labs=0D=0AMichigan State University;East Lansing;MI;48824;USA
fn:Gerd Kortemeyer
end:vcard



Redirecting a multipart/form-data POST request

2001-01-15 Thread Darren Stuart Embry

I am writing a program that needs to process form data, (here's
the kicker) which is sometimes multipart/form-data, then
redirect a user to a GET request (which doesn't need to process
the form data).  I would like to use the standard mechanism for
issuing a redirect, for other reasons:

$r-header_out('Location' = $url);
return REDIRECT;

I have discovered two ways to achieve redirects from a POST
request if its content is application/x-www-form-urlencoded:

- $r-print() the headers manually and have the handler return
  DONE or HTTP_OK.  This nasty hack is what I am doing at this
  time so I can get redirects from multipart/form-data to
  somehow work.

- convert the POST request to a GET and redirect the standard
  way.  I don't understand why forcing a read of all the data
  coming in from the HTTP request allows redirects to work, but
  it does.

When I do neither, i.e., leave the POST request as is and use
the standard redirect mechanism, the browser hangs and the
server actually does not send the redirect until I hit the Stop
button (I'm using ngrep to determine this).  This also happens
if I use the $r-print($header) method and still return
REDIRECT.

The second method allows me to revert to the use of the default
redirect mechanism, but unfortunately does not work with
multipart/form-data.  I would *really* like to be able to use
the standard redirection mechanism for other reasons.  From the
Apache man page:

   $r-content
   The $r-content method will return the entity body
   read from the client, but only if the request content
   type is `application/x-www-form-urlencoded'.
   ...

Is there a similar technique I can use to read all the
multipart/form-data from the socket and then allow CGI.pm to
continue to process it, and would this work?

Thank you,
Darren

-- 
Darren Stuart Embry.  Kicking down some kind examples of how to keep
your karma clean.  http://www.webonastick.com/
``I base most of my fashion taste on what doesn't itch.''
--- Gilda Radner



Re: Redirecting a multipart/form-data POST request

2001-01-15 Thread Ask Bjoern Hansen

On Mon, 15 Jan 2001, Darren Stuart Embry wrote:

[...] 
 When I do neither, i.e., leave the POST request as is and use
 the standard redirect mechanism, the browser hangs and the
 server actually does not send the redirect until I hit the Stop
 button (I'm using ngrep to determine this).  This also happens
 if I use the $r-print($header) method and still return
 REDIRECT.

Try adding 

$r-method('GET');
$r-headers_in-unset('Content-length');

to your code before doing the return REDIRECT.


 - ask

-- 
ask bjoern hansen - http://ask.netcetera.dk/
more than 70M impressions per day, http://valueclick.com