Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r386]: branches / 0.71 / lib / XMLRPC / Transport / HTTP.pm Maximize Restore History

Download this file

HTTP.pm    197 lines (130 with data), 5.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# ======================================================================
#
# Copyright (C) 2000-2001 Paul Kulchenko (paulclinger@yahoo.com)
# SOAP::Lite is free software; you can redistribute it
# and/or modify it under the same terms as Perl itself.
#
# $Id: HTTP.pm 386 2011-08-18 19:48:31Z kutterma $
#
# ======================================================================
package XMLRPC::Transport::HTTP;
use strict;
our $VERSION = 0.714;
use XMLRPC::Lite;
use SOAP::Transport::HTTP;
# ======================================================================
package XMLRPC::Transport::HTTP::CGI;
@XMLRPC::Transport::HTTP::CGI::ISA = qw(SOAP::Transport::HTTP::CGI);
sub initialize; *initialize = \&XMLRPC::Server::initialize;
sub make_fault {
local $SOAP::Constants::HTTP_ON_FAULT_CODE = 200;
shift->SUPER::make_fault(@_);
}
sub make_response {
local $SOAP::Constants::DO_NOT_USE_CHARSET = 1;
shift->SUPER::make_response(@_);
}
# ======================================================================
package XMLRPC::Transport::HTTP::Daemon;
@XMLRPC::Transport::HTTP::Daemon::ISA = qw(SOAP::Transport::HTTP::Daemon);
sub initialize; *initialize = \&XMLRPC::Server::initialize;
sub make_fault; *make_fault = \&XMLRPC::Transport::HTTP::CGI::make_fault;
sub make_response; *make_response = \&XMLRPC::Transport::HTTP::CGI::make_response;
# ======================================================================
package XMLRPC::Transport::HTTP::Apache;
@XMLRPC::Transport::HTTP::Apache::ISA = qw(SOAP::Transport::HTTP::Apache);
sub initialize; *initialize = \&XMLRPC::Server::initialize;
sub make_fault; *make_fault = \&XMLRPC::Transport::HTTP::CGI::make_fault;
sub make_response; *make_response = \&XMLRPC::Transport::HTTP::CGI::make_response;
# ======================================================================
1;
__END__
=head1 NAME
XMLRPC::Transport::HTTP - Server/Client side HTTP support for XMLRPC::Lite
=head1 SYNOPSIS
=over 4
=item Client
use XMLRPC::Lite
proxy => 'http://localhost/',
# proxy => 'http://localhost/cgi-bin/xmlrpc.cgi', # local CGI server
# proxy => 'http://localhost/', # local daemon server
# proxy => 'http://login:password@localhost/cgi-bin/xmlrpc.cgi', # local CGI server with authentication
;
print getStateName(1);
=item CGI server
use XMLRPC::Transport::HTTP;
my $server = XMLRPC::Transport::HTTP::CGI
-> dispatch_to('methodName')
-> handle
;
=item Daemon server
use XMLRPC::Transport::HTTP;
my $daemon = XMLRPC::Transport::HTTP::Daemon
-> new (LocalPort => 80)
-> dispatch_to('methodName')
;
print "Contact to XMLRPC server at ", $daemon->url, "\n";
$daemon->handle;
=back
=head1 DESCRIPTION
This class encapsulates all HTTP related logic for a XMLRPC server,
independent of what web server it's attached to.
If you want to use this class you should follow simple guideline
mentioned above.
=head2 PROXY SETTINGS
You can use any proxy setting you use with LWP::UserAgent modules:
XMLRPC::Lite->proxy('http://endpoint.server/',
proxy => ['http' => 'http://my.proxy.server']);
or
$xmlrpc->transport->proxy('http' => 'http://my.proxy.server');
should specify proxy server for you. And if you use C<HTTP_proxy_user>
and C<HTTP_proxy_pass> for proxy authorization SOAP::Lite should know
how to handle it properly.
=head2 COOKIE-BASED AUTHENTICATION
use HTTP::Cookies;
my $cookies = HTTP::Cookies->new(ignore_discard => 1);
# you may also add 'file' if you want to keep them between sessions
my $xmlrpc = XMLRPC::Lite->proxy('http://localhost/');
$xmlrpc->transport->cookie_jar($cookies);
Cookies will be taken from response and provided for request. You may
always add another cookie (or extract what you need after response)
with HTTP::Cookies interface.
You may also do it in one line:
$xmlrpc->proxy('http://localhost/',
cookie_jar => HTTP::Cookies->new(ignore_discard => 1));
=head2 COMPRESSION
XMLRPC::Lite provides you option for enabling compression on wire (for HTTP
transport only). Both server and client should support this capability,
but this logic should be absolutely transparent for your application.
Server will respond with encoded message only if client can accept it
(client sends Accept-Encoding with 'deflate' or '*' values) and client
has fallback logic, so if server doesn't understand specified encoding
(Content-Encoding: deflate) and returns proper error code
(415 NOT ACCEPTABLE) client will repeat the same request not encoded and
will store this server in per-session cache, so all other requests will
go there without encoding.
Having options on client and server side that let you specify threshold
for compression you can safely enable this feature on both client and
server side.
Compression will be enabled on client side IF: threshold is specified AND
size of current message is bigger than threshold AND module Compress::Zlib
is available. Client will send header 'Accept-Encoding' with value 'deflate'
if threshold is specified AND module Compress::Zlib is available.
Server will accept compressed message if module Compress::Zlib is available,
and will respond with compressed message ONLY IF: threshold is specified AND
size of current message is bigger than threshold AND module Compress::Zlib
is available AND header 'Accept-Encoding' is presented in request.
=head1 DEPENDENCIES
Crypt::SSLeay for HTTPS/SSL
HTTP::Daemon for XMLRPC::Transport::HTTP::Daemon
Apache, Apache::Constants for XMLRPC::Transport::HTTP::Apache
=head1 SEE ALSO
See ::CGI, ::Daemon and ::Apache for implementation details.
See examples/XMLRPC/* for examples.
=head1 COPYRIGHT
Copyright (C) 2000-2001 Paul Kulchenko. All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 AUTHOR
Paul Kulchenko (paulclinger@yahoo.com)
=cut