You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Honza Pazdziora <ad...@informatics.muni.cz> on 2004/08/18 13:37:03 UTC

Raw header and body of HTTP request

Hello,

I'm using Apache2, mod_perl2. I use Apache::Request, so that I can get
to ->args and ->body data easily.

At the same time, I would sometimes need to get the raw body data. For
example, an application may process both
application/x-www-form-urlencoded and SOAP requests. However, once the
data was $r->read it seems to be lost.

Is there any way to retrieve the raw content (and headers) of the
HTTP request in mod_perl2, and have this raw access coexist with
Apache::Request? Or is this a bad application design on my side and
should I always have separate handlers for separate access methods?

Yours,

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
 .project: Perl, mod_perl, DBI, Oracle, large Web systems, XML/XSL, ...
		Only self-confident people can be simple.

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Raw header and body of HTTP request

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Honza Pazdziora <ad...@informatics.muni.cz> writes:

> I'm using Apache2, mod_perl2. I use Apache::Request, so that I can get
> to ->args and ->body data easily.
> 
> At the same time, I would sometimes need to get the raw body data.

If the body data is getting lost when you use Apache::Request
in mp2, that's a bug in Apache::Request.

[...]

> Is there any way to retrieve the raw content (and headers)

You could write a input filter that goes in front of HTTP_IN
(protocol or connection type), which would see the byte stream 
in raw form (headers unparsed, data unchunked).


-- 
Joe Schaefer


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Raw header and body of HTTP request

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:

> Be sure you've got
> 
>   use Apache::RequestRecIO;
                       ^^^

Sorry, typo- should be Apache::RequestIO.

-- 
Joe Schaefer


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Raw header and body of HTTP request

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Honza Pazdziora <ad...@informatics.muni.cz> writes:

[...]

> and it works great. However, I'm probably missing something but how
> do you do equivalent of $r->read($buffer, 64_000) multiple times? 

Be sure you've got

  use Apache::RequestRecIO;

somewhere, and everything should work just fine.  If not,
please file a bug report.

-- 
Joe Schaefer


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Raw header and body of HTTP request

Posted by Honza Pazdziora <ad...@informatics.muni.cz>.
On Wed, Aug 18, 2004 at 04:59:09PM +0200, Honza Pazdziora wrote:
> 
> I have httpd-apreq / Apache::Request in my setup, in fact what I do
> is basically
> 
> 	use Apache::Request ();
> 	my $request = Apache::Request->new($r);
> 	if ($r->method eq 'POST') {
> 		# process $request->param and $request->body
> 	} elsif ($r->method eq 'GET') {
> 		# process $request->args
> 	}
> 
> and it works great. However, I'm probably missing something but how do
> you do equivalent of $r->read($buffer, 64_000) multiple times? I can
> create multiple Apache::Request objects based on one $r just fine but
> that does not seem to give me the raw message body, does it?

So far, the only solution I came with is to write input filter which
will gather the raw content of the HTTP request in temporary variable,
and if asked for the raw data, force read until is_eos and then
return whatever was collected in the storage. Does is sound like
a reasonable thing to do?

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
 .project: Perl, mod_perl, DBI, Oracle, large Web systems, XML/XSL, ...
		Only self-confident people can be simple.

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Raw header and body of HTTP request

Posted by Honza Pazdziora <ad...@informatics.muni.cz>.
On Wed, Aug 18, 2004 at 09:53:17AM -0400, Geoffrey Young wrote:
> 
> hi honza, a flash from the past :)

Past flash stuck here between POSTs, GETs, SOAPs, etc. ;-)

> > Is there any way to retrieve the raw content (and headers) of the
> > HTTP request in mod_perl2, and have this raw access coexist with
> > Apache::Request? Or is this a bad application design on my side and
> > should I always have separate handlers for separate access methods?
> 
> see the httpd-apreq project (aka libapreq, Apache::Request, mod_apreq).
> 
>   http://httpd.apache.org/apreq/
> 
> mod_apreq allows you to read the message body multiple times over the course
> of the request, which is what it sounds like you are after.

I have httpd-apreq / Apache::Request in my setup, in fact what I do
is basically

	use Apache::Request ();
	my $request = Apache::Request->new($r);
	if ($r->method eq 'POST') {
		# process $request->param and $request->body
	} elsif ($r->method eq 'GET') {
		# process $request->args
	}

and it works great. However, I'm probably missing something but how do
you do equivalent of $r->read($buffer, 64_000) multiple times? I can
create multiple Apache::Request objects based on one $r just fine but
that does not seem to give me the raw message body, does it?

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
 .project: Perl, mod_perl, DBI, Oracle, large Web systems, XML/XSL, ...
		Only self-confident people can be simple.

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Raw header and body of HTTP request

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>I'm using Apache2, mod_perl2. I use Apache::Request, so that I can get
>>to ->args and ->body data easily.

> see the httpd-apreq project (aka libapreq, Apache::Request, mod_apreq).

eesh, I think I need to read these messages a but more closely next time

;)

sorry.

--Geoff

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Raw header and body of HTTP request

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Honza Pazdziora wrote:
> Hello,

hi honza, a flash from the past :)

> 
> I'm using Apache2, mod_perl2. I use Apache::Request, so that I can get
> to ->args and ->body data easily.
> 
> At the same time, I would sometimes need to get the raw body data. For
> example, an application may process both
> application/x-www-form-urlencoded and SOAP requests. However, once the
> data was $r->read it seems to be lost.
> 
> Is there any way to retrieve the raw content (and headers) of the
> HTTP request in mod_perl2, and have this raw access coexist with
> Apache::Request? Or is this a bad application design on my side and
> should I always have separate handlers for separate access methods?

see the httpd-apreq project (aka libapreq, Apache::Request, mod_apreq).

  http://httpd.apache.org/apreq/

mod_apreq allows you to read the message body multiple times over the course
of the request, which is what it sounds like you are after.

HTH

--Geoff

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html