Re: [PATCH] extension for HTTP/Cookies.pm
Ward Vandewege <[EMAIL PROTECTED]> writes: > Yes there must be. I've tried the test program you sent in a > previous message, and it works fine here (standalone, no > mod-perl). But HTTP-Webtest nor Monkeywrench see the cookies my > application sends. > > OK, I found out why. Apparently my mod-perl application sends > responses to the browser _without any headers_, not even a 'HTTP/1.x > 200 OK'. This is probably illegal, but none of the browsers seem to > have a problem with it (except for some older IE versions, but they > are completely hopeless anyway). It is not really illegal. It can be regarded as just being HTTP version pre-1.0 (which LWP calls "HTTP/0.9"). But this is not a general problem with mod-perl applications. There must be something wrong with your server side configuration or scripts. Perhaps you should enable the "PerlSendHeader" option on the server? > So LWP has a problem attaching the META header fields to an empty > header. It does generate the following lines apparently: > > HTTP/0.9 200 OK > Client-Date: Thu, 06 Sep 2001 10:25:10 GMT > Client-Peer: 127.0.0.1:80 > > Fair enough, I guess, if empty headers are illegal. Again, I would not call it illegal, but LWP only looks into the document if it is told it is HTML. In &LWP::Procotcol::collect you will find: if ($parse_head && $response->content_type eq 'text/html') { $parser = HTML::HeadParser->new($response->{'_headers'}); } One way to "fix" this would be to apply some extra heuristics in the collect() function to figure out if this really is HTML when the content-type header is missing. One could look at the suffix of the request URI or perhaps peek into the document. But I'm not sure it is worth it. Isn't it better to just fix the server to supply the header. Regards, Gisle
Re: [PATCH] extension for HTTP/Cookies.pm
Ward Vandewege <[EMAIL PROTECTED]> writes: > The problem is that I'm trying to use it on non-LWP generated > web-pages. I was playing with the HTTP-Webtest module and the > Monkeywrench module to build a test-suite for some web-application > that I've built. It uses META-style cookies only, without copying > them into the headers. Both HTTP-Webtest and Monkeywrench use libwww > to parse the results of their queries and hence don't understand > this. Parsing of stuff happen on the client side. Therefore picking up cookies embedded in the HTML should already work. Both of HTTP-Webtest and Monkeywrench use LWP in the standard way. If they don't pick up your cookies, then there must be a bug somewhere. > I imagine there may be more websites that do this - and as far > as I know Apache isn't smart enough to generate proper cookie > headers from the META-style cookies. LWP does not rely on the server to move meta stuff into the HTTP response headers. It looks into HTML documents (on the client side) by itself. > So what now? I think there may be a need for HTTP::Cookie to > understand raw META-style cookies - at least I could use that... It is always possible to just invoke the HTML::HeadParser directly on the response before you pass it off to HTTP::Cookies if you obtained from something else than a $ua->request() call. Regards, Gisle
Re: [PATCH] extension for HTTP/Cookies.pm
use LWP::UserAgent; use HTTP::Cookies; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new); my $res = $ua->request(HTTP::Request->new(GET => "http://localhost/xxx.html";)); print $res->as_string; print "-\n", $ua->cookie_jar->as_string, "-\n"; $res = $ua->request(HTTP::Request->new(TRACE => "http://localhost/";)); print $res->as_string; HTTP/1.1 200 OK Connection: close Date: Wed, 05 Sep 2001 21:30:54 GMT Accept-Ranges: bytes Server: Apache/1.3.12 (Unix) (Red Hat/Linux) Content-Length: 84 Content-Type: text/html ETag: "2499a-54-3b9694de" Last-Modified: Wed, 05 Sep 2001 21:10:54 GMT Client-Date: Wed, 05 Sep 2001 21:30:54 GMT Client-Peer: 127.0.0.1:80 Set-Cookie: hash=KMvJWfpPpqhgOEdU This is some text. - Set-Cookie3: hash=KMvJWfpPpqhgOEdU; path="/"; domain="localhost.local"; discard; version=0 - HTTP/1.1 200 OK Connection: close Date: Wed, 05 Sep 2001 21:30:54 GMT Server: Apache/1.3.12 (Unix) (Red Hat/Linux) Content-Type: message/http Client-Date: Wed, 05 Sep 2001 21:30:54 GMT Client-Peer: 127.0.0.1:80 TRACE / HTTP/1.0 Cookie: hash=KMvJWfpPpqhgOEdU Cookie2: $Version="1" Host: localhost User-Agent: libwww-perl/5.5395