line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Webrobot::Ext::XHtml::HTTP::Response; |
2
|
1
|
|
|
1
|
|
23950
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Author: Stefan Trcek |
6
|
|
|
|
|
|
|
# Copyright(c) 2004 ABAS Software AG |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# extend LWPs HTTP::Response without subclassing |
10
|
|
|
|
|
|
|
package HTTP::Response; |
11
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
12
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
1197
|
use HTML::TreeBuilder; |
|
1
|
|
|
|
|
39558
|
|
|
1
|
|
|
|
|
14
|
|
15
|
1
|
|
|
1
|
|
655
|
use WWW::Webrobot::UseXPath; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use WWW::Webrobot::Html2XHtml; |
17
|
|
|
|
|
|
|
use WWW::Webrobot::MyEncode qw/octet_to_internal_utf8/; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
WWW::Webrobot::WebrobotLoad - Run testplans with multiple clients |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use WWW::Webrobot::Ext::XHtml::HTTP::Response; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This module extends the L module. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item content_charset |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This method extracts the charset which is encoded in the HTTP header |
39
|
|
|
|
|
|
|
'content-type' field. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
'content-type' => 'text/plain; charset=utf-8' |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
yields 'utf-8'. |
44
|
|
|
|
|
|
|
However, the content-type field may be a scalar as in the example above |
45
|
|
|
|
|
|
|
or an array of scalars. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
If a content-type is set within the HTTP header B an HTML document |
48
|
|
|
|
|
|
|
you will get an array with two scalars: |
49
|
|
|
|
|
|
|
The first comes from the HTTP header and the second from the document. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This method extract the first content-type which is set. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub content_charset { |
56
|
|
|
|
|
|
|
my ($r) = @_; |
57
|
|
|
|
|
|
|
return undef if ! $r; |
58
|
|
|
|
|
|
|
# $r->content_encoding() isn't ok, so do it myself; |
59
|
|
|
|
|
|
|
my $coding = undef; |
60
|
|
|
|
|
|
|
if ($r and my $ct = $r->headers->{'content-type'}) { |
61
|
|
|
|
|
|
|
$ct = [ $ct ] if ref $ct ne "ARRAY"; |
62
|
|
|
|
|
|
|
CODING: |
63
|
|
|
|
|
|
|
foreach (@$ct) { |
64
|
|
|
|
|
|
|
if (m/;\s*charset\s*=\s*([^\s;]*)/) { |
65
|
|
|
|
|
|
|
$coding = $1; |
66
|
|
|
|
|
|
|
last CODING; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
return $coding; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item content_xhtml |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns an XML file |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
If called with an argument it is interpreted as a boolean method |
79
|
|
|
|
|
|
|
that returns 1 if an xhtml content is set. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub content_xhtml { |
84
|
|
|
|
|
|
|
my ($self, $arg) = @_; |
85
|
|
|
|
|
|
|
return $self -> {_content_xhtml} ? 1 : 0 if defined $arg; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if (! exists $self -> {_content_xhtml}) { |
88
|
|
|
|
|
|
|
my $content = $self->content; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $xhtml; |
91
|
|
|
|
|
|
|
foreach ($self->content_type()) { |
92
|
|
|
|
|
|
|
/^text\/html$/ and do { |
93
|
|
|
|
|
|
|
my $encoding = $self->content_charset(); |
94
|
|
|
|
|
|
|
my $parser = WWW::Webrobot::Html2XHtml->new(); |
95
|
|
|
|
|
|
|
$xhtml = $parser->to_xhtml($content, $encoding); |
96
|
|
|
|
|
|
|
last; |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
/text\/xml$/ || /^application\/xml$/ || /^application\/xhtml+xml$/ and do { |
99
|
|
|
|
|
|
|
$xhtml = $content; |
100
|
|
|
|
|
|
|
}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
$self -> {_content_xhtml} = $xhtml; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return $self -> {_content_xhtml}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item content_encoded |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Ccontent> returns a sequence of octets. |
111
|
|
|
|
|
|
|
This method makes it a perl string according to the specified encoding. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
See L. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub content_encoded { |
118
|
|
|
|
|
|
|
my ($self, $arg) = @_; |
119
|
|
|
|
|
|
|
return $self -> {_content_encoded} ? 1 : 0 if $arg; |
120
|
|
|
|
|
|
|
if (! exists $self -> {_content_encoded}) { |
121
|
|
|
|
|
|
|
my $encoding = $self->content_charset(); |
122
|
|
|
|
|
|
|
my $content_encoded = octet_to_internal_utf8($encoding, $self->content); |
123
|
|
|
|
|
|
|
$self -> {_content_encoded} = $content_encoded; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return $self -> {_content_encoded}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item xpath |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Applies an XPath expression to L. |
132
|
|
|
|
|
|
|
The XPath expression builder will be cached, |
133
|
|
|
|
|
|
|
as it is a B operation. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub xpath { |
138
|
|
|
|
|
|
|
my ($self, $expr) = @_; |
139
|
|
|
|
|
|
|
my $xml = $self->content_xhtml(); |
140
|
|
|
|
|
|
|
return undef if !$xml; |
141
|
|
|
|
|
|
|
$self->{_xpath} = WWW::Webrobot::UseXPath->new($xml) if !exists $self->{_xpath}; |
142
|
|
|
|
|
|
|
return $self -> {_xpath} -> extract($expr); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=pod |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |