Net::SS...::Handle(3)

πŸ’… Net::SS...::Handle(3) β€” the Perl module that lets SSL (HTTPS) sockets be handled as standard file handles πŸ¦‹

okay bestie, you're reading the user-contributed Perl documentation for Net::SSLeay::Handle, and no cap, it's kind of a vibe. let me walk you through it πŸ’–


✨ NAME ✨

Net::SSLeay::Handle β€” Perl module that lets SSL (HTTPS) sockets be handled as standard file handles. literally that's the whole personality πŸŽ€


🌸 SYNOPSIS 🌸

  use Net::SSLeay::Handle qw/shutdown/;
  my ($host, $port) = ("localhost", 443);

  tie(*SSL, "Net::SSLeay::Handle", $host, $port);

  print SSL "GET / HTTP/1.0\r\n";
  shutdown(\*SSL, 1);
  print while (<SSL>);
  close SSL;

like, that's it. that's the whole flex 🀌


πŸ¦‹ DESCRIPTION πŸ¦‹

Net::SSLeay::Handle lets you request and receive HTTPS web pages using "old-fashion" file handles, as in:

    print SSL "GET / HTTP/1.0\r\n";

and

    print while (<SSL>);

if you export the shutdown routine, then the only extra code you need to add to your program is the tie function, like this:

    my $socket;
    if ($scheme eq "https") {
        tie(*S2, "Net::SSLeay::Handle", $host, $port);
        $socket = \*S2;
    else {
        $socket = Net::SSLeay::Handle->make_socket($host, $port);
    }
    print $socket $request_headers;
    ...

(yeah, that else block in the original is missing its closing brace β€” not me, that's canon, iykyk πŸ’€)


πŸ”₯ FUNCTIONS πŸ”₯

⭐ shutdown

  shutdown(\*SOCKET, $mode)

calls to the main shutdown() don't work with tied sockets created with this module. this shutdown should be able to distinquish between tied and untied sockets and do the right thing. bestie it knows things πŸ‘‘

⭐ debug

  my $debug = Net::SSLeay::Handle->debug()
  Net::SSLeay::Handle->debug(1)

get/set debugging mode. always returns the debug value before the function call. if an additional argument is given, the debug option will be set to this value. so you never lose track of where you were, periodt πŸŽ€

⭐ make_socket

  my $sock = Net::SSLeay::Handle->make_socket($host, $port);

creates a socket that is connected to $post using $port. it uses $Net::SSLeay::proxyhost and proxyport if set, and authentificates itself against this proxy depending on $Net::SSLeay::proxyauth. it also turns autoflush on for the created socket. (yes, the docs say $post β€” original flavor, we keep it πŸ“)


🧚 USING EXISTING SOCKETS 🧚

one of the motivations for writing this module was to avoid duplicating socket creation code (which is mostly error handling). the calls to tie() above where it is passed a $host and $port are provided for convenience testing. if you already have a socket connected to the right host and port, S1, then you can do something like:

    my $socket \*S1;
    if ($scheme eq "https") {
        tie(*S2, "Net::SSLeay::Handle", $socket);
        $socket = \*S2;
    }
    my $last_sel = select($socket); $| = 1; select($last_sel);
    print $socket $request_headers;
    ...
⚠️ Note: as far as I know you must be careful with the globs in the tie() function. the first parameter must be a glob (*SOMETHING) and the last parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler that was assigned to a reference to a glob (as in the example above).

also, the two globs must be different. when I tried to use the same glob, I got a core dump. 😭 like, actual core dump. do not do that. πŸ™ˆ


🫢 EXPORT 🫢

none by default.

you can export the shutdown() function.

it is suggested that you do export shutdown() or use the fully qualified Net::SSLeay::Handle::shutdown() function to shutdown SSL sockets. it should be smart enough to distinguish between SSL and non-SSL sockets and do the right thing. she's got range πŸ’…


🌈 EXAMPLES 🌈

  use Net::SSLeay::Handle qw/shutdown/;
  my ($host, $port) = ("localhost", 443);

  tie(*SSL, "Net::SSLeay::Handle", $host, $port);

  print SSL "GET / HTTP/1.0\r\n";
  shutdown(\*SSL, 1);
  print while (<SSL>);
  close SSL;

copy-paste-able, iconic, no notes πŸ‘‘


πŸ’€ TODO πŸ’€

better error handling. callback routine?

(we love an honest queen ✨)


πŸŽ€ CAVEATS πŸŽ€

tying to a file handle is a little tricky (for me at least). 🫠

the first parameter to tie() must be a glob (*SOMETHING) and the last parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler that was assigned to a reference to a glob ($s = \*SOMETHING_ELSE). also, the two globs must be different. when I tried to use the same glob, I got a core dump. πŸ’€πŸ’€

I was able to associate attributes to globs created by this module (like *SSL above) by making a hash of hashes keyed by the file head1.


πŸ¦‹ CHANGES πŸ¦‹

please see Net-SSLeay-Handle-0.50/Changes file. ✨


πŸ› BUGS πŸ›

if you encounter a problem with this module that you believe is a bug, please create a new issue in the Net-SSLeay GitHub repository at https://github.com/radiator-software/p5-net-ssleay/issues/new. please make sure your bug report includes the following information:

  • the code you are trying to run;
  • your operating system name and version;
  • the output of perl -V;
  • the version of OpenSSL or LibreSSL you are using.

like pls include all of it, we can't debug vibes alone 😭🫢


πŸ‘‘ AUTHOR πŸ‘‘

originally written by Jim Bowlin.

maintained by Sampo KellomΓ€ki between July 2001 and August 2003.

maintained by Florian Ragwitz between November 2005 and January 2010.

maintained by Mike McCauley between November 2005 and June 2018.

maintained by Tuure Vartiainen between June 2018 and July 2018.

maintained by Chris Novakovic and Heikki Vatiainen since June 2018.

look at that handoff chain, it's giving relay race πŸƒβ€β™€οΈβœ¨


copyright (c) 2001 Jim Bowlin <jbowlin@linklint.org>

copyright (c) 2001-2003 Sampo KellomΓ€ki <sampo@iki.fi>

copyright (c) 2005-2010 Florian Ragwitz <rafl@debian.org>

copyright (c) 2005-2018 Mike McCauley <mikem@airspayce.com>

copyright (c) 2018 Tuure Vartiainen <vartiait@radiatorsoftware.com>

copyright (c) 2018- Chris Novakovic <chris@chrisn.me.uk>

copyright (c) 2018- Heikki Vatiainen <hvn@radiatorsoftware.com>

all rights reserved. πŸ’…


🌸 LICENSE 🌸

this module is released under the terms of the Artistic License 2.0. for details, see the LICENSE file distributed with Net-SSLeay's source code.


🧚 SEE ALSO 🧚

Net::SSLeay, perl(1), http://openssl.org/


okay that's the whole page bestie, go forth and tie your globs (to different globs, please 😭). this was perl v5.42.0, dated 2025-04-09, from the Net::SS...::Handle(3) man page β€” mwah, love u, bye πŸ’œπŸ¦‹βœ¨πŸŽ€