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.
Echoes back request headers and body as JSON.
curl -k -v -H "foo:bar" https://localhost:3443/echoSends repeated test pattern of specified size (in bytes).
# Download 1MB of repeated data
curl -k -v -H "x-repeat-data: 1000000" https://localhost:3443/echoSends repeated data throttled to ~900 bytes/sec (for timeout testing).
# Download 5MB slowly at default speed (900 bytes/sec)
curl -k -v -H "x-repeat-data: 5000000" -H "x-slow-response: true" https://localhost:3443/echoOverride default throughput with x-throughput-bps header.
# Download 5MB at 500 bytes/sec
curl -k -v -H "x-repeat-data: 5000000" -H "x-slow-response: true" -H "x-throughput-bps: 500" https://localhost:3443/echoReturns the byte count of the uploaded body without echoing the body content.
# Upload data and get byte count
curl -k -v -X PUT -H "x-upload-test: true" -d "test data" https://localhost:3443/echoReturns the specified HTTP status code.
# Get a 500 status code
curl -k -v -H "x-expect-status: 500" https://localhost:3443/echoReturns 404 Not Found.
- 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.
Install the required Python dependencies:
pip install trio h11Or using pip3:
pip3 install trio h11Run both HTTP (port 8081) and HTTPS (port 8082) servers:
python3 mock_server.pyRun on a custom port without sudo:
HTTP_PORT=8080 HTTPS_PORT=8443 python3 mock_server.pyImportant: Since this uses a self-signed certificate, clients must disable peer verification.
- Any path: Echoes request body as JSON
- /response-headers?HeaderName=value: Adds custom headers to the response based on query parameters
Press Ctrl+C to gracefully shut down the server.