Debian Codegraph @

crt/aws-c-http/tests/mock_server/README.md

raw symbols SCIP
1 # HTTP2 Local server
2
3 Local server based on [python-hyper/h2](https://github.com/python-hyper/h2).
4
5 ## How to run the server
6
7 Python 3.5+ required.
8
9 * Install hyper h2 python module. `python3 -m pip install h2`
10
11 ### TLS server
12
13 * The code is based the [example](https://github.com/python-hyper/h2/blob/master/examples/asyncio/asyncio-server.py) from hyper h2 server.
14 * 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.
15 * Run python. `python3 ./server.py`.
16
17 #### Endpoint
18
19 ##### `/echo` - Echo endpoint (default)
20
21 Echoes back request headers and body as JSON.
22
23 ```bash
24 curl -k -v -H "foo:bar" https://localhost:3443/echo
25 ```
26 #### Special headers
27
28 ##### `/echo` with `x-repeat-data` header - Download test
29
30 Sends repeated test pattern of specified size (in bytes).
31
32 ```bash
33 # Download 1MB of repeated data
34 curl -k -v -H "x-repeat-data: 1000000" https://localhost:3443/echo
35 ```
36
37 ##### `/echo` with `x-repeat-data` + `x-slow-response` headers - Slow connection test
38
39 Sends repeated data throttled to ~900 bytes/sec (for timeout testing).
40
41 ```bash
42 # Download 5MB slowly at default speed (900 bytes/sec)
43 curl -k -v -H "x-repeat-data: 5000000" -H "x-slow-response: true" https://localhost:3443/echo
44 ```
45
46 ##### `/echo` with custom throughput - Custom speed test
47
48 Override default throughput with `x-throughput-bps` header.
49
50 ```bash
51 # Download 5MB at 500 bytes/sec
52 curl -k -v -H "x-repeat-data: 5000000" -H "x-slow-response: true" -H "x-throughput-bps: 500" https://localhost:3443/echo
53 ```
54
55 ##### `/echo` with `x-upload-test` header - Upload test
56
57 Returns the byte count of the uploaded body without echoing the body content.
58
59 ```bash
60 # Upload data and get byte count
61 curl -k -v -X PUT -H "x-upload-test: true" -d "test data" https://localhost:3443/echo
62 ```
63
64 ##### `/echo` with `x-expect-status` header - Custom status code
65
66 Returns the specified HTTP status code.
67
68 ```bash
69 # Get a 500 status code
70 curl -k -v -H "x-expect-status: 500" https://localhost:3443/echo
71 ```
72
73 ##### Any other path
74
75 Returns 404 Not Found.
76
77 ### Non-TLS server
78
79 - The code is based the non-tls [example](http://python-hyper.org/projects/h2/en/stable/basic-usage.html) from hyper h2 server.
80 - Run python. `python3 ./non_tls_server.py`.
81 - To test the server runs correctly, you can do `curl -v --http2-prior-knowledge http://localhost:3280` and check the result.
82
83 # HTTP1.1 Local server
84
85 ## Requirements
86
87 Install the required Python dependencies:
88
89 ```bash
90 pip install trio h11
91 ```
92
93 Or using pip3:
94
95 ```bash
96 pip3 install trio h11
97 ```
98
99 ## Running the Server
100
101 ### Basic Usage (HTTP + HTTPS)
102
103 Run both HTTP (port 8081) and HTTPS (port 8082) servers:
104
105 ```bash
106 python3 mock_server.py
107 ```
108
109 ### Custom Ports
110
111 Run on a custom port without sudo:
112
113 ```bash
114 HTTP_PORT=8080 HTTPS_PORT=8443 python3 mock_server.py
115 ```
116
117 **Important**: Since this uses a self-signed certificate, clients must disable peer verification.
118
119 ## Endpoints
120
121 - **Any path**: Echoes request body as JSON
122 - **/response-headers?HeaderName=value**: Adds custom headers to the response based on query parameters
123
124 ## Stopping the Server
125
126 Press `Ctrl+C` to gracefully shut down the server.