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 1
1
Revision history for HTTP-Message
2
2
3
3
{{$NEXT}}
4
+ - If an object is passed to HTTP::Request, it must provide a canonical()
5
+ method (Olaf Alders)
4
6
5
7
6.11 2015-09-09
6
8
- 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
65
65
Carp::croak(" A URI can't be a " . ref ($uri ) . " reference" )
66
66
if ref ($uri ) eq ' HASH' or ref ($uri ) eq ' ARRAY' ;
67
67
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 ' ) ;
69
69
$uri = $uri -> clone;
70
70
unless ($HTTP::URI_CLASS eq " URI" ) {
71
71
# Argh!! Hate this... old LWP legacy!
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ use strict;
5
5
use warnings;
6
6
7
7
use Test::More;
8
- plan tests => 11;
8
+ use Test::Fatal qw( dies_ok lives_ok ) ;
9
+ plan tests => 15;
9
10
10
11
use HTTP::Request;
11
12
@@ -31,3 +32,41 @@ is($r2->method, "DELETE");
31
32
is($r2 -> uri, " http:" );
32
33
is($r2 -> protocol, " HTTP/1.1" );
33
34
is($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