1Net::SSLeay::Handle(3)User Contributed Perl DocumentationNet::SSLeay::Handle(3)
2
3
4
6 Net::SSLeay::Handle - Perl module that lets SSL (HTTPS) sockets be
7 handled as standard file handles.
8
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
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
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
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
113 Better error handling. Callback routine?
114
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
128 Please see Net-SSLeay-Handle-0.50/Changes file.
129
131 If you encounter a problem with this module that you believe is a bug,
132 please create a new issue <https://github.com/radiator-software/p5-net-
133 ssleay/issues/new> in the Net-SSLeay GitHub repository. Please make
134 sure your bug report includes the following information:
135
136 • the code you are trying to run;
137
138 • your operating system name and version;
139
140 • the output of "perl -V";
141
142 • the version of OpenSSL or LibreSSL you are using.
143
145 Originally written by Jim Bowlin.
146
147 Maintained by Sampo Kellomäki between July 2001 and August 2003.
148
149 Maintained by Florian Ragwitz between November 2005 and January 2010.
150
151 Maintained by Mike McCauley between November 2005 and June 2018.
152
153 Maintained by Chris Novakovic, Tuure Vartiainen and Heikki Vatiainen
154 since June 2018.
155
157 Copyright (c) 2001 Jim Bowlin <jbowlin@linklint.org>
158
159 Copyright (c) 2001-2003 Sampo Kellomäki <sampo@iki.fi>
160
161 Copyright (c) 2005-2010 Florian Ragwitz <rafl@debian.org>
162
163 Copyright (c) 2005-2018 Mike McCauley <mikem@airspayce.com>
164
165 Copyright (c) 2018- Chris Novakovic <chris@chrisn.me.uk>
166
167 Copyright (c) 2018- Tuure Vartiainen <vartiait@radiatorsoftware.com>
168
169 Copyright (c) 2018- Heikki Vatiainen <hvn@radiatorsoftware.com>
170
171 All rights reserved.
172
174 This module is released under the terms of the Artistic License 2.0.
175 For details, see the "LICENSE" file distributed with Net-SSLeay's
176 source code.
177
179 Net::SSLeay, perl(1), http://openssl.org/
180
181
182
183perl v5.36.0 2023-01-20 Net::SSLeay::Handle(3)