Use the nghttp2 Python module from Homebrew from pyenv's Python

Premise

Although pyenv mainly uses python2, it also has a python3 environment.

How to get nghttp2 with Python modules

brew install nghttp2 --with-python3

If you have already put it in without a module

brew reinstall nghttp2 --with-python3

Used in python specified by pyenv

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

Use the nghttp2 Python module from Homebrew from pyenv's Python
Use thingsspeak from python
Use fluentd from python
Use MySQL from Python
Use MySQL from Python
Use BigQuery from python.
Use mecab-ipadic-neologd from python
How to use the Raspberry Pi relay module Python
I wanted to use the Python library from MATLAB
[Blender] Use the text drawing module from within the script
Let's use the Python version of the Confluence API module.
Call your own python module from the ROS package
Install the latest Python from pyenv installed with homebrew
About the Python module venv
Use MySQL from Anaconda (python)
Install pyenv from Homebrew, install Python from pyenv
Use e-Stat API from Python
Use Stanford Core NLP from Python
How to use the optparse module
Existence from the viewpoint of Python
Read and use Python files from Python
Forcibly use Google Translate from python
Change the Python version of Homebrew
Use kabu StationĀ® API from Python
Use Azure Blob Storage from Python
Try using the Python Cmd module
Sakura Use Python on the Internet
Use fastText trained model from Python
Use Google Analytics API from Python
Master the weakref module in Python
Operate Maya from an external Python interpreter using the rpyc module
You can also use virtualenv from the IntelliJ IDEA Python plugin
Use PostgreSQL data type (jsonb) from Python
Tips for Python beginners to use the Scikit-image example for themselves 9 Use from C
Use machine learning APIs A3RT from Python
Learning notes from the beginning of Python 1
I want to use jar from python
Use Google Cloud Vision API from Python
[Blender] Use OpenGL from inside the script
[Python] Import the module one level higher
Check the path of the Python imported module
Launch the Python interpreter from Git bash
Use Python external module on Sakura Internet
Use Django from a local Python script
From Python 3.4, pip becomes the standard installer! ??
Use C ++ functions from python with pybind11
Learning notes from the beginning of Python 2
Install the Python module in any directory
[Python] Get the main color from the screenshot
Use the LibreOffice app in Python (2) Manipulate calc (from macros and externals)
How to use the C library in Python
Get the contents of git diff from python
Firebase: Use Cloud Firestore and Cloud Storage from Python
Study from Python Hour7: How to use classes
[Python] Let's execute the module regularly using schedule
Specify the Python executable to use with virtualenv
Use logger with Python for the time being
[Bash] Use here-documents to get python power from bash
Wrap C with Cython for use from Python
Use cryptography module to handle OpenSSL in Python
Use Python in your environment from Win Automation