File tree Expand file tree Collapse file tree 3 files changed +108
-2
lines changed Expand file tree Collapse file tree 3 files changed +108
-2
lines changed Original file line number Diff line number Diff line change @@ -48,12 +48,40 @@ http_filters:
48
48
- name : sample # before envoy.router because order matters!
49
49
typed_config :
50
50
" @type " : type.googleapis.com/sample.Decoder
51
- key : via
51
+ key : Via
52
52
val : sample-filter
53
53
- name : envoy.router
54
54
typed_config : {}
55
55
` ` `
56
-
56
+ or you can just use this demo yaml file [config.yaml](config.yaml).
57
+ - Run envoy with this cmd:
58
+ ` ` ` sh
59
+ ./bazel-bin/envoy --config-path ./http-filter-example/config.yaml -l trace
60
+ ```
61
+ - Run an http server
62
+ ``` sh
63
+ python httpserver.py
64
+ ```
65
+ - Access the http server with curl cmd:
66
+ ``` sh
67
+ curl http://127.0.0.1:8080
68
+ ```
69
+ You can find there is an kv string in the request header to the http server,
70
+ and the key value ` Via ` has become to ` via ` , you can see the request header
71
+ in the http server stdout.
72
+ ``` sh
73
+ $ python httpserver.py
74
+ Started httpserver on port 8081
75
+ 127.0.0.1 - - [29/Sep/2020 11:30:03] " GET / HTTP/1.1" 200 -
76
+ host: 127.0.0.1:8080
77
+ user-agent: curl/7.58.0
78
+ accept: * /*
79
+ x-forwarded-proto: http
80
+ x-request-id: b7a8d227-77a0-4985-a121-5e0f70bd16f2
81
+ via: sample-filter
82
+ x-envoy-expected-rq-timeout-ms: 15000
83
+ content-length: 0
84
+ ```
57
85
58
86
[ StreamDecoderFilter ] : https://github.com/envoyproxy/envoy/blob/b2610c84aeb1f75c804d67effcb40592d790e0f1/include/envoy/http/filter.h#L300
59
87
[ 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
+ admin :
2
+ access_log_path : /dev/null
3
+ address :
4
+ socket_address :
5
+ address : 127.0.0.1
6
+ port_value : 0
7
+ static_resources :
8
+ clusters :
9
+ name : cluster_0
10
+ connect_timeout : 0.25s
11
+ load_assignment :
12
+ cluster_name : cluster_0
13
+ endpoints :
14
+ - lb_endpoints :
15
+ - endpoint :
16
+ address :
17
+ socket_address :
18
+ address : 127.0.0.1
19
+ port_value : 8081
20
+ listeners :
21
+ - name : listener_0
22
+ address :
23
+ socket_address :
24
+ address : 127.0.0.1
25
+ port_value : 8080
26
+ filter_chains :
27
+ - filters :
28
+ - name : envoy.http_connection_manager
29
+ typed_config :
30
+ " @type " : type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
31
+ stat_prefix : ingress_http
32
+ codec_type : auto
33
+ route_config :
34
+ name : local_route
35
+ virtual_hosts :
36
+ - name : local_service
37
+ domains :
38
+ - " *"
39
+ routes :
40
+ - match :
41
+ prefix : " /"
42
+ route :
43
+ cluster : cluster_0
44
+ http_filters :
45
+ - name : sample # before envoy.router because order matters!
46
+ typed_config :
47
+ " @type " : type.googleapis.com/sample.Decoder
48
+ key : vIa
49
+ val : sample-filter
50
+ - name : envoy.router
51
+ typed_config : {}
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+ from BaseHTTPServer import BaseHTTPRequestHandler ,HTTPServer
3
+
4
+ PORT = 8081
5
+
6
+ class doHandler (BaseHTTPRequestHandler ):
7
+ # Handler for the GET requests
8
+ def do_GET (self ):
9
+ self .send_response (200 )
10
+ self .send_header ('Content-type' ,'text/html' )
11
+ self .end_headers ()
12
+ print self .headers # print the http header
13
+ # Send the html message
14
+ self .wfile .write ("Hello World !" )
15
+ return
16
+
17
+ 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
+
22
+ # Wait forever for incoming http requests
23
+ server .serve_forever ()
24
+
25
+ except KeyboardInterrupt :
26
+ print 'shutting down the web server'
27
+ server .socket .close ()
You can’t perform that action at this time.
0 commit comments