Skip to content
Back to top

# Example wsgiserver_ssl.py

     1#!/usr/bin/python
     2"""Secure WSGI server example based on gevent.pywsgi"""
     3
     4from __future__ import print_function
     5from gevent import pywsgi
     6
     7
     8def hello_world(env, start_response):
     9    if env['PATH_INFO'] == '/':
    10        start_response('200 OK', [('Content-Type', 'text/html')])
    11        return [b"<b>hello world</b>"]
    12
    13    start_response('404 Not Found', [('Content-Type', 'text/html')])
    14    return [b'<h1>Not Found</h1>']
    15
    16print('Serving on https://:8443')
    17# see src/gevent/tests/test__ssl.py for how to generate
    18server = pywsgi.WSGIServer(('127.0.0.1', 8443), hello_world, keyfile='server.key', certfile='server.crt')
    19# to start the server asynchronously, call server.start()
    20# we use blocking serve_forever() here because we have no other jobs
    21server.serve_forever()

Current source