File Coverage

blib/lib/SOAP/WSDL/Transport/HTTP.pm
Criterion Covered Total %
statement 33 33 100.0
branch 8 8 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 49 50 98.0


line stmt bran cond sub pod time code
1             package SOAP::WSDL::Transport::HTTP;
2 2     2   13837 use strict; use warnings;
  2     2   2  
  2         52  
  2         6  
  2         2  
  2         44  
3 2     2   6 use base qw(LWP::UserAgent);
  2         3  
  2         5951  
4              
5             our $VERSION = 3.003;
6              
7             # create methods normally inherited from SOAP::Client
8 2         243 SUBFACTORY: {
9 2     2   87871 no strict qw(refs);
  2         3  
10             foreach my $method ( qw(code message status is_success) ) {
11             *{ $method } = sub {
12 23     23   131 my $self = shift;
13 23 100       37 return $self->{ $method } if not @_;
14 20         32 return $self->{ $method } = shift;
15             };
16             }
17             }
18              
19             sub _agent {
20 3     3   190 return qq[SOAP::WSDL $VERSION];
21             }
22              
23             sub send_receive {
24 4     4 0 12 my ($self, %parameters) = @_;
25 4         8 my ($envelope, $soap_action, $endpoint, $encoding, $content_type) =
26             @parameters{qw(envelope action endpoint encoding content_type)};
27              
28 4 100       7 $encoding = defined($encoding)
29             ? lc($encoding)
30             : 'utf-8';
31              
32 4 100       24 $content_type = "text/xml; charset=$encoding"
33             if not defined($content_type);
34             # what's this all about?
35             # unfortunately combination of LWP and Perl 5.6.1 and later has bug
36             # in sending multibyte characters. LWP uses length() to calculate
37             # content-length header and starting 5.6.1 length() calculates chars
38             # instead of bytes. 'use bytes' in THIS file doesn't work, because
39             # it's lexically scoped. Unfortunately, content-length we calculate
40             # here doesn't work either, because LWP overwrites it with
41             # content-length it calculates (which is wrong) AND uses length()
42             # during syswrite/sysread, so we are in a bad shape anyway.
43             #
44             # what to do? we calculate proper content-length (using
45             # bytelength() function from SOAP::Utils) and then drop utf8 mark
46             # from string (doing pack with 'C0A*' modifier) if length and
47             # bytelength are not the same
48              
49             # use bytes is lexically scoped
50 2     2   481 my $bytelength = do { use bytes; length $envelope };
  2         9  
  2         10  
  4         5  
  4         5  
51 4 100       14 $envelope = pack('C0A*', $envelope)
52             if length($envelope) != $bytelength;
53              
54 4         18 my $request = HTTP::Request->new( 'POST',
55             $endpoint,
56             [ 'Content-Type', "$content_type",
57             'Content-Length', $bytelength,
58             'SOAPAction', $soap_action,
59             ],
60             $envelope );
61              
62 4         393 my $response = $self->request( $request );
63              
64 4         1098 $self->code( $response->code);
65 4         8 $self->message( $response->message);
66 4         7 $self->is_success($response->is_success);
67 4         7 $self->status($response->status_line);
68              
69 4         11 return $response->content();
70             }
71              
72             1;
73              
74             =pod
75              
76             =head1 NAME
77              
78             SOAP::WSDL::Transport::HTTP - Fallback http(s) transport class
79              
80             =head1 DESCRIPTION
81              
82             Provides a thin transport class used by SOAP::WSDL::Transport when
83             SOAP::Lite is not available.
84              
85             =head1 LICENSE AND COPYRIGHT
86              
87             Copyright (c) 2007 Martin Kutter. All rights reserved.
88              
89             This file is part of SOAP-WSDL. You may distribute/modify it under
90             the same terms as perl itself
91              
92             =head1 AUTHOR
93              
94             Martin Kutter Emartin.kutter fen-net.deE
95              
96             =head1 REPOSITORY INFORMATION
97              
98             $Rev: 851 $
99             $LastChangedBy: kutterma $
100             $Id: HTTP.pm 851 2009-05-15 22:45:18Z kutterma $
101             $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Transport/HTTP.pm $
102              
103             =cut
104