Skip to content

Commit 4d6287a

Browse files
committed
add verity script
1 parent 2831af1 commit 4d6287a

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

http-filter-example/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ or you can just use this demo yaml file [config.yaml](config.yaml).
6060
```
6161
- Run an http server
6262
```sh
63-
python httpserver.py
63+
python ./http-filter-example/httpserver.py
6464
```
6565
- Access the http server with curl cmd:
6666
```sh
@@ -82,6 +82,10 @@ via: sample-filter
8282
x-envoy-expected-rq-timeout-ms: 15000
8383
content-length: 0
8484
```
85+
- Start service and verify with shell script
86+
87+
1. `bash ./http-filter-example/start_service.sh`
88+
2. `bash ./http-filter-example/verify.sh`
8589

8690
[StreamDecoderFilter]: https://github.com/envoyproxy/envoy/blob/b2610c84aeb1f75c804d67effcb40592d790e0f1/include/envoy/http/filter.h#L300
8791
[StreamEncoderFilter]: https://github.com/envoyproxy/envoy/blob/b2610c84aeb1f75c804d67effcb40592d790e0f1/include/envoy/http/filter.h#L413

http-filter-example/httpserver.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
#!/usr/bin/python
2-
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
1+
#!/usr/bin/python3
2+
from http.server import BaseHTTPRequestHandler,HTTPServer
33

4-
PORT = 8081
4+
HTTP_PORT = 8081
55

6+
# This class will handles any incoming request
67
class doHandler(BaseHTTPRequestHandler):
8+
79
# Handler for the GET requests
810
def do_GET(self):
911
self.send_response(200)
1012
self.send_header('Content-type','text/html')
1113
self.end_headers()
12-
print self.headers # print the http header
13-
# Send the html message
14-
self.wfile.write("Hello World !")
14+
print(self.headers)
15+
# Send the message
16+
self.wfile.write(b"Hello World !\r\n")
17+
self.wfile.write(self.headers.as_bytes())
1518
return
1619

1720
try:
18-
# Create a web server and define the handler to manage the incoming request
19-
server = HTTPServer(('', PORT), doHandler)
20-
print 'Started httpserver on port ' , PORT
21+
# Create a http server and define the handler to manage the request
22+
server = HTTPServer(('', HTTP_PORT), doHandler)
23+
print('Started httpserver on port ' , HTTP_PORT)
2124

2225
# Wait forever for incoming http requests
2326
server.serve_forever()
2427

2528
except KeyboardInterrupt:
26-
print 'shutting down the web server'
29+
print('^C received, shutting down the web server')
2730
server.socket.close()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
python3 ./http-filter-example/httpserver.py&
3+
./bazel-bin/envoy --config-path ./http-filter-example/config.yaml

http-filter-example/verify.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash -e
2+
3+
export NAME=http-filter-example
4+
5+
_curl () {
6+
local arg curl_command
7+
curl_command=(curl -s)
8+
if [[ ! "$*" =~ "-X" ]]; then
9+
curl_command+=(-X GET)
10+
fi
11+
for arg in "${@}"; do
12+
curl_command+=("$arg")
13+
done
14+
"${curl_command[@]}" || {
15+
echo "ERROR: curl (${curl_command[*]})" >&2
16+
return 1
17+
}
18+
}
19+
20+
responds_with () {
21+
local expected
22+
expected="$1"
23+
shift
24+
_curl "${@}" | grep "$expected" || {
25+
echo "ERROR: curl expected (${*}): $expected" >&2
26+
return 1
27+
}
28+
}
29+
30+
responds_with \
31+
"via: sample-filter" \
32+
"http://localhost:8080"

0 commit comments

Comments
 (0)