File tree Expand file tree Collapse file tree 4 files changed +53
-11
lines changed
Expand file tree Collapse file tree 4 files changed +53
-11
lines changed Original file line number Diff line number Diff 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
8282x-envoy-expected-rq-timeout-ms: 15000
8383content-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
Original file line number Diff line number Diff line change 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
67class 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
1720try :
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
2528except KeyboardInterrupt :
26- print ' shutting down the web server'
29+ print ( '^C received, shutting down the web server')
2730 server .socket .close ()
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ python3 ./http-filter-example/httpserver.py&
3+ ./bazel-bin/envoy --config-path ./http-filter-example/config.yaml
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments