File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 11Revision history for HTTP-Message
22
33{{$NEXT}}
4+ - If an object is passed to HTTP::Request, it must provide a canonical()
5+ method (Olaf Alders)
46
576.11 2015-09-09
68 - fix an undefined value warning in HTTP::Headers::as_string
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ sub uri
6565 Carp::croak(" A URI can't be a " . ref ($uri ) . " reference" )
6666 if ref ($uri ) eq ' HASH' or ref ($uri ) eq ' ARRAY' ;
6767 Carp::croak(" Can't use a " . ref ($uri ) . " object as a URI" )
68- unless $uri -> can(' scheme' );
68+ unless $uri -> can(' scheme' ) && $uri -> can( ' canonical ' ) ;
6969 $uri = $uri -> clone;
7070 unless ($HTTP::URI_CLASS eq " URI" ) {
7171 # Argh!! Hate this... old LWP legacy!
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ use strict;
55use warnings;
66
77use Test::More;
8- plan tests => 11;
8+ use Test::Fatal qw( dies_ok lives_ok ) ;
9+ plan tests => 15;
910
1011use HTTP::Request;
1112
@@ -31,3 +32,41 @@ is($r2->method, "DELETE");
3132is($r2 -> uri, " http:" );
3233is($r2 -> protocol, " HTTP/1.1" );
3334is($r2 -> header(" Accept-Encoding" ), $req -> header(" Accept-Encoding" ));
35+
36+ # Test objects which are accepted as URI-like
37+ {
38+ package Foo::URI ;
39+
40+ use strict;
41+ use warnings;
42+
43+ sub new { return bless {}, shift ; }
44+ sub clone { return shift }
45+ sub scheme { }
46+
47+ 1;
48+
49+ package Foo::URI::WithCanonical ;
50+
51+ sub new { return bless {}, shift ; }
52+ sub clone { return shift }
53+ sub scheme { }
54+ sub canonical { }
55+
56+ 1;
57+
58+ package main ;
59+
60+ ok( Foo::URI-> new-> can( ' scheme' ), ' Object can scheme()' );
61+ dies_ok(
62+ sub { HTTP::Request-> new( GET => Foo::URI-> new ) },
63+ ' Object without canonical method triggers an exception'
64+ );
65+
66+ ok( Foo::URI::WithCanonical-> new-> can( ' canonical' ),
67+ ' Object can canonical()' );
68+ lives_ok(
69+ sub { HTTP::Request-> new( GET => Foo::URI::WithCanonical-> new ) },
70+ ' Object with canonical method does not trigger an exception'
71+ );
72+ }
You can’t perform that action at this time.
0 commit comments