http / ssl basics Part 2 WSGIServer

http / ssl basics Part 2 WSGIServer
Photo by Caspar Camille Rubin / Unsplash

Most developers now use existing  Web Frameworks and few (really rarely any) develop from scratch.  But would it not be excellent to be able to develop your own web framework w/ SSL support native.  There is scant documentation on the wsgiserver, but these work!

Template code:

import wsgiserver

page = '<!DOCTYPE html><html><body><a href=https://www.somewhereovertherainbow.com>This is a link</a></body></html>'

def my_app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/html; charset=utf-8')]
    start_response(status, response_headers)
    return [page.encode('utf-8')]

server = wsgiserver.WSGIServer(my_app, host='0.0.0.0', port=8080)
server.start()

One can easily add SSL by simply:

server = wsgiserver.WSGIServer(my_app, certfile='cert.pem', keyfile='privkey.pem')

No matter what one types it will serve the page!

The little bit of found documentation:

WSGIserver
A high-speed, production ready, thread pooled, generic WSGI server with SSL support
Linux Rocks Every Day