develooper Front page | perl.poe | Postings from February 2003

Re: Can't get response code from POE::Component::Client::HTTP in streaming mode

Thread Previous | Thread Next
From:
Ilya Martynov
Date:
February 24, 2003 13:54
Subject:
Re: Can't get response code from POE::Component::Client::HTTP in streaming mode
Message ID:
87k7fpnybh.fsf@abra.ru
>>>>> On Sun, 23 Feb 2003 23:29:49 +0300, Ilya Martynov <ilya@martynov.org> said:

>>>>> On Sun, 23 Feb 2003 12:27:37 -0500, Rocco Caputo <troc@netrus.net> said:
RC> On Sun, Feb 23, 2003 at 10:07:30AM +0300, Ilya Martynov wrote:
>>> 
>>> I'm trying to write HTTP proxy with POE so I've tried to use
>>> POE::Component::Client::HTTP to proxy HTTP requests to the actual web
>>> servers. The problem is that I don't see how I can get response code
>>> and message (i.e. '200 Ok', '404 Not Found', etc) from web server when
>>> I use POE::Component::Client::HTTP in streaming mode as in streaming
>>> mode response handler only recieves HTTP::Headers object which doesn't
>>> have this information. I've checked sources/docs to find any
>>> workaround but I've not found anything. Am I missing something?

RC> I think you're right.  HTTP::Headers doesn't include the status code.
RC> Client::HTTP needs to do something else, but I'm not sure what.
RC> Suggestions are welcome.

IM> It could just return HTTP::Response object like in non-streaming mode.

See parch after my signature which implements this. Downside is that
it breaks some backward compatiblity.

-- 
Ilya Martynov,  ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support
UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org

--- POE-Component-Client-HTTP-0.51/HTTP.pm	Tue Dec  3 00:03:32 2002
+++ POE-Component-Client-HTTP-0.51-statuscode/HTTP.pm	Tue Feb 25 00:24:33 2003
@@ -633,11 +633,11 @@
       $heap->{cookie_jar}->extract_cookies($request->[REQ_RESPONSE]);
     }
 
-    # If we're streaming, the response is HTTP::Headers and undef to
-    # signal the end of the stream.  Otherwise it's the entire
-    # HTTP::Response object we've carefully built.
+    # If we're streaming, the response is HTTP::Response without
+    # content and undef to signal the end of the stream.  Otherwise
+    # it's the entire HTTP::Response object we've carefully built.
     if ($heap->{streaming}) {
-      $request->[REQ_POSTBACK]->( $request->[REQ_RESPONSE]->headers(),
+      $request->[REQ_POSTBACK]->( $request->[REQ_RESPONSE],
                                   undef
                                 );
     }
@@ -802,7 +802,7 @@
     # Otherwise add the new octets to the response's content.  -><-
     # This should only add up to content-length octets total!
     if ($heap->{streams}) {
-      $request->[REQ_POSTBACK]->( $request->[REQ_RESPONSE]->headers(),
+      $request->[REQ_POSTBACK]->( $request->[REQ_RESPONSE],
                                   $request->[REQ_BUFFER]
                                 );
     }
@@ -990,11 +990,11 @@
     # HTTP::Request
     my $request_object  = $request_packet->[0];
 
-    # HTTP::Response or HTTP::Headers (if streaming)
+    # HTTP::Response
     my $response_object = $response_packet->[0];
 
     my $stream_chunk;
-    if ($response_object->isa("HTTP::Headers")) {
+    if (! defined($response_object->content)) {
       $stream_chunk = $response_packet->[1];
     }
 
@@ -1116,8 +1116,9 @@
 
 When C<Streaming> is set to nonzero, however, the response handler
 receives chunks of up to OCTETS octets apiece.  The response handler
-accepts slightly different parameters in this case.  ARG0 is an
-HTTP::Headers object, and ARG1 contains a a chunk of raw response
+accepts slightly different parameters in this case.  ARG0 is also an
+HTTP::Response object but it does not contain response content,
+and ARG1 contains a a chunk of raw response
 content, or undef if the stream has ended.
 
   sub streaming_response_handler {

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About