Although pyenv mainly uses python2, it also has a python3 environment.
brew install nghttp2 --with-python3
If you have already put it in without a module
brew reinstall nghttp2 --with-python3
The code below
-Let's write an HTTP / 2 server in Python --Qiita
This is the code that made the code directly written by the author of nghttp2 work according to the current nghttp2.
import ssl
import nghttp2
class Handler(nghttp2.BaseRequestHandler):
def on_headers(self):
res = b'nghttp2 FTW\n'
self.send_response(status=200,
#headers = [('content-length', str(len(res)))],
headers = [('content-type', 'text/plain')],
body=res)
# SSL/To enable TLS,Certificate server.crt,Private key server.in the key file
#Save,Enable the following 3 lines, nghttp2.Specify ctx for the HTTP2Server ssl parameter.
# ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
# ctx.options = ssl.OP_ALL | ssl.OP_NO_SSLv2
# ctx.load_cert_chain('server.crt', 'server.key')
server = nghttp2.HTTP2Server(('127.0.0.1', 8080), Handler, ssl=None)
server.serve_forever()
PYTHONPATH=/usr/local/lib/python3.5/site-packages python server.py &
nghttp http://127.0.0.1:8080/
Recommended Posts