Local server based on python-hyper/h2.
Python 3.5+ required.
- Install hyper h2 python module.
python3 -m pip install h2
- The code is based the example from hyper h2 server.
- Have the cert/key ready. The script now using
../resources/unittests.crt, you can either just run the script within this directory, which will find the certificates and key from the related path, or you can use your own and change the code coordinately. - Run python.
python3 ./server.py.
- Minor changed based on the example to response the headers of requests back within the headers from
/echo. - To test the server runs correctly, you can do
curl -k -v -H "foo:bar" https://localhost:3443/echoand check the result.
- To test download, when
:pathis/downloadTest, server will response a repeated string with lengthself.download_test_length, which is 2,500,000,000 now. It will be repeats of sting "This is CRT HTTP test." - To test the server runs correctly, you can do
curl -k -v -H "foo:bar" https://localhost:3443/downloadTestand check the result.
- Simulate a slow connection when
:pathis/slowConnTest. The speed is controlled byout_bytes_per_second. Default speed is 900 B/s, which will send 900 bytes of data and wait a sec to send new 900 bytes of data.
- To test upload, when
:methodisPOSTorPUT, server will response the length received from response body - To test the server runs correctly, you can do
curl -k -X POST -F'data=@upload_test.txt' https://localhost:3443/upload_testwhereupload_test.txtis file to upload.
- The code is based the non-tls example from hyper h2 server.
- Run python.
python3 ./non_tls_server.py. - To test the server runs correctly, you can do
curl -v --http2-prior-knowledge http://localhost:3280and check the result.