1Net::SSLeay::Handle(3)User Contributed Perl DocumentationNet::SSLeay::Handle(3)
2
3
4

NAME

6       Net::SSLeay::Handle - Perl module that lets SSL (HTTPS) sockets be
7       handled as standard file handles.
8

SYNOPSIS

10         use Net::SSLeay::Handle qw/shutdown/;
11         my ($host, $port) = ("localhost", 443);
12
13         tie(*SSL, "Net::SSLeay::Handle", $host, $port);
14
15         print SSL "GET / HTTP/1.0\r\n";
16         shutdown(\*SSL, 1);
17         print while (<SSL>);
18         close SSL;
19

DESCRIPTION

21       Net::SSLeay::Handle allows you to request and receive HTTPS web pages
22       using "old-fashion" file handles as in:
23
24           print SSL "GET / HTTP/1.0\r\n";
25
26       and
27
28           print while (<SSL>);
29
30       If you export the shutdown routine, then the only extra code that you
31       need to add to your program is the tie function as in:
32
33           my $socket;
34           if ($scheme eq "https") {
35               tie(*S2, "Net::SSLeay::Handle", $host, $port);
36               $socket = \*S2;
37           else {
38               $socket = Net::SSLeay::Handle->make_socket($host, $port);
39           }
40           print $socket $request_headers;
41           ...
42

FUNCTIONS

44       shutdown
45             shutdown(\*SOCKET, $mode)
46
47           Calls to the main shutdown() don't work with tied sockets created
48           with this module.  This shutdown should be able to distinquish
49           between tied and untied sockets and do the right thing.
50
51       debug
52             my $debug = Net::SSLeay::Handle->debug()
53             Net::SSLeay::Handle->debug(1)
54
55           Get/set debugging mode. Always returns the debug value before the
56           function call.  if an additional argument is given the debug option
57           will be set to this value.
58
59       make_socket
60             my $sock = Net::SSLeay::Handle->make_socket($host, $port);
61
62           Creates a socket that is connected to $post using $port. It uses
63           $Net::SSLeay::proxyhost and proxyport if set and authentificates
64           itself against this proxy depending on $Net::SSLeay::proxyauth. It
65           also turns autoflush on for the created socket.
66
67   USING EXISTING SOCKETS
68       One of the motivations for writing this module was to avoid duplicating
69       socket creation code (which is mostly error handling).  The calls to
70       tie() above where it is passed a $host and $port is provided for
71       convenience testing.  If you already have a socket connected to the
72       right host and port, S1, then you can do something like:
73
74           my $socket \*S1;
75           if ($scheme eq "https") {
76               tie(*S2, "Net::SSLeay::Handle", $socket);
77               $socket = \*S2;
78           }
79           my $last_sel = select($socket); $| = 1; select($last_sel);
80           print $socket $request_headers;
81           ...
82
83       Note: As far as I know you must be careful with the globs in the tie()
84       function.  The first parameter must be a glob (*SOMETHING) and the last
85       parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler
86       that was assigned to a reference to a glob (as in the example above)
87
88       Also, the two globs must be different.  When I tried to use the same
89       glob, I got a core dump.
90
91   EXPORT
92       None by default.
93
94       You can export the shutdown() function.
95
96       It is suggested that you do export shutdown() or use the fully
97       qualified Net::SSLeay::Handle::shutdown() function to shutdown SSL
98       sockets.  It should be smart enough to distinguish between SSL and non-
99       SSL sockets and do the right thing.
100

EXAMPLES

102         use Net::SSLeay::Handle qw/shutdown/;
103         my ($host, $port) = ("localhost", 443);
104
105         tie(*SSL, "Net::SSLeay::Handle", $host, $port);
106
107         print SSL "GET / HTTP/1.0\r\n";
108         shutdown(\*SSL, 1);
109         print while (<SSL>);
110         close SSL;
111

TODO

113       Better error handling.  Callback routine?
114

CAVEATS

116       Tying to a file handle is a little tricky (for me at least).
117
118       The first parameter to tie() must be a glob (*SOMETHING) and the last
119       parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler
120       that was assigned to a reference to a glob ($s = \*SOMETHING_ELSE).
121       Also, the two globs must be different.  When I tried to use the same
122       glob, I got a core dump.
123
124       I was able to associate attributes to globs created by this module
125       (like *SSL above) by making a hash of hashes keyed by the file head1.
126
127       Support for old perls may not be 100%. If in trouble try 5.6.0 or
128       newer.
129

CHANGES

131       Please see Net-SSLeay-Handle-0.50/Changes file.
132

KNOWN BUGS

134       If you let this module construct sockets for you with Perl versions
135       below v.5.6 then there is a slight memory leak.  Other upgrade your
136       Perl, or create the sockets yourself.  The leak was created to let
137       these older versions of Perl access more than one Handle at a time.
138

AUTHOR

140       Jim Bowlin jbowlin@linklint.org
141

SEE ALSO

143       Net::SSLeay, perl(1), http://openssl.org/
144
145
146
147perl v5.28.1                      2016-10-31            Net::SSLeay::Handle(3)
Impressum