1

I am trying to make an ssl https server with ruby. I already have server code that works fine over http that can parse requests, send back formatted data, etc. I would like to be able to read a key from a file (like what I would get from ZeroSSL or something) and have it such that when I visit localhost:80 it is using ssl.

My current code:

require "socket"

server = TCPServer.new($HOST, $PORT)
puts "Server listening on #{$HOST}:#{$PORT.to_s}"
c = server.accept
<Request parser (probably irrelevant and long so I left it out)>
client.print "HTTP/1.1 200\r\n"
client.print "Content-Type: text/html\r\n"
client.print "\r\n"
client.print "<HTML HERE>"

There is a lot more code that I left out that was for probably irrelevant things like generating responses, reading client data, etc. that seemed the same in the OpenSSL::SSLServer documentation.

Matthias Lee
  • 89
  • 2
  • 7

0 Answers0