fix for URI v1.18?
Looks to me like line 46 in heuristic.t should have www.perl.bv instead of www.perl.org. grier
LWP::UserAgent fails for non-http and attached cookie jar
Hi there, if the LWP::UserAgent has a cookie jar attached to it, it should only use it for http/https requests -- in case we're fetching ftp: or file: or other URLs, it should keep the cookie jar untouched, just like a regular browser does. With LWP 5.64, if you try this: use LWP::UserAgent; use HTTP::Cookies; my $ua = LWP::UserAgent-new(); my $jar = HTTP::Cookies-new(); $ua-cookie_jar($jar); my $resp = $ua-get(file://etc/passwd); you'll get Can't locate object method port via package URI::file Fix (checks for http/s scheme before using the cookie jar in UserAgent.pm) and a test case for t/base/cookies.t are appended below. -- Mike Mike Schilli [EMAIL PROTECTED] http://perlmeister.com diff -Naur lwp5/lib/LWP/UserAgent.pm lwp5.new/lib/LWP/UserAgent.pm --- lwp5/lib/LWP/UserAgent.pm Tue Dec 11 13:11:29 2001 +++ lwp5.new/lib/LWP/UserAgent.pm Tue Mar 5 23:49:13 2002 @@ -393,7 +393,8 @@ $last = 0 if $last 0; # there is no way to actually request no content $request-init_header('Range' = bytes=0-$last); } -$cookie_jar-add_cookie_header($request) if $cookie_jar; +$cookie_jar-add_cookie_header($request) if $cookie_jar and +$request-uri-scheme() =~ /^https?$/; return($request); } diff -Naur lwp5/t/base/cookies.t lwp5.new/t/base/cookies.t --- lwp5/t/base/cookies.t Thu Feb 7 11:08:08 2002 +++ lwp5.new/t/base/cookies.t Tue Mar 5 23:47:24 2002 @@ -1,6 +1,7 @@ -print 1..36\n; +print 1..37\n; #use LWP::Debug '+'; +use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request; use HTTP::Response; @@ -598,6 +599,18 @@ $counter{session_before} == 0; #print $c-as_string; print ok 36\n; + +#--- +# Verify the LWP::UserAgent works with the cookie jar attached + +my $ua = LWP::UserAgent-new(); +$c = HTTP::Cookies-new(); +$ua-cookie_jar($c); +my $resp = $ua-get(file://this/file/does/not/exist); +if($resp-is_success()) { +print not ; +} +print ok 37\n; #---
Re: hi
On Tue, Mar 05, 2002 at 06:54:41AM -0800, Randal L. Schwartz wrote: Reinier == Reinier Post [EMAIL PROTECTED] writes: Reinier On Mon, Mar 04, 2002 at 04:33:37PM +0530, kavitha malar wrote: I want to search a text in a website how to do that through perl. Reinierperl -MLWP::Simple -e \ Reinier 'getprint http://www.google.com/search?q=$word+site:$site' Reinier I'm serious. (This is what I use to find my own pages.) Except now, Google has gotten fairly upset about automated page fetches. There's a thread on use.perl.org about it. Thanks for the pointer. http://www.google.com/terms_of_service.html is pretty vague about it. As someone in the thread remarked, we are talking about a single query here, for personal use, without even any reformatting of the results. And last time I checked, Google *specifically* blocks the default agent type that LWP uses, so you'll get no response. You have to change the agent type to something with Mozilla in it. :) Mmm, I should have checked that. I actually feed the Google query URL to lynx or links. Gisle - would it be unfair to have a special useragent string when LWP detects that it is visiting Google? :) Nice idea :) But hidden magic in code is always bad. -- Reinier
Re: Unexpected error messages in FTP request
On Wed, Mar 06, 2002 at 11:44:52AM +1000, Mark Suter wrote: When I run the following code I get an unexpected error message. The larger the file to be downloaded, the more often the error is repeated. Use of uninitialized value in addition (+) at /usr/share/perl5/Net/FTP/I.pm line 29. It's fixed in libnet 1.10 Maurice
Re: fix for URI v1.18?
On Tue, Mar 05, 2002 at 09:57:30PM -0500, Grier Ellis wrote: Looks to me like line 46 in heuristic.t should have www.perl.bv instead of www.perl.org. You mean instead of .com? $URI::Heuristic::MY_COUNTRY = bv; print not unless uf_urlstr(perl/camel.gif) eq http://www.perl.com/camel.gif;; print ok 6\n; The problem is www.perl.bv doesn't resolve so it falls back to .com. Maybe change it to www.perl.ca. Maurice
Re: parse headers returned
Sean M. Burke wrote: I've been trying to decide which would be better: $resp-status line or $resp-request-url . -- . $resp-status_line or $resp-status_line . ' at ' . $resp-request-url If this is to be used partly as a debugging aid then I like bracketing the returned data because that way I get to see clearly if there are unexpected trailing whitespace or other junk. This is kind of a hangover from programming in languages that were less than perfect at string handling but it could still be useful. no? This would imply an option 4/5 of $resp-request-url . '--(' . $resp-status_line .')' or '('.$resp-status_line . ') at ' . $resp-request-url Of which my personal favourite would be 4 Francis -- Francis Turner, CIO Juelich Enzyme Products GmbH http://www.juelich-enzyme.com/ +49-173-291-7278 If you're not part of the solution, you're part of the precipitate. -- Henry J. Tillman
Re: fix for URI v1.18?
Maurice Aubrey [EMAIL PROTECTED] writes: On Tue, Mar 05, 2002 at 09:57:30PM -0500, Grier Ellis wrote: Looks to me like line 46 in heuristic.t should have www.perl.bv instead of www.perl.org. You mean instead of .com? $URI::Heuristic::MY_COUNTRY = bv; print not unless uf_urlstr(perl/camel.gif) eq http://www.perl.com/camel.gif;; print ok 6\n; The problem is www.perl.bv doesn't resolve so it falls back to .com. Maybe change it to www.perl.ca. It is not supposed to resolve in test 6. It test that the fall back to .com works as it should. Regards, Gisle