-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: helight <[email protected]>
- Loading branch information
Showing
4 changed files
with
53 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
#!/usr/bin/python | ||
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer | ||
#!/usr/bin/python3 | ||
from http.server import BaseHTTPRequestHandler,HTTPServer | ||
|
||
PORT = 8081 | ||
HTTP_PORT = 8081 | ||
|
||
# This class will handles any incoming request | ||
class doHandler(BaseHTTPRequestHandler): | ||
|
||
# Handler for the GET requests | ||
def do_GET(self): | ||
self.send_response(200) | ||
self.send_header('Content-type','text/html') | ||
self.end_headers() | ||
print self.headers # print the http header | ||
# Send the html message | ||
self.wfile.write("Hello World !") | ||
print(self.headers) | ||
# Send the message | ||
self.wfile.write(b"Hello World !\r\n") | ||
self.wfile.write(self.headers.as_bytes()) | ||
return | ||
|
||
try: | ||
# Create a web server and define the handler to manage the incoming request | ||
server = HTTPServer(('', PORT), doHandler) | ||
print 'Started httpserver on port ' , PORT | ||
# Create a http server and define the handler to manage the request | ||
server = HTTPServer(('', HTTP_PORT), doHandler) | ||
print('Started httpserver on port ' , HTTP_PORT) | ||
|
||
# Wait forever for incoming http requests | ||
server.serve_forever() | ||
|
||
except KeyboardInterrupt: | ||
print 'shutting down the web server' | ||
print('^C received, shutting down the web server') | ||
server.socket.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
python3 ./http-filter-example/httpserver.py& | ||
./bazel-bin/envoy --config-path ./http-filter-example/config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash -e | ||
|
||
export NAME=http-filter-example | ||
|
||
_curl () { | ||
local arg curl_command | ||
curl_command=(curl -s) | ||
if [[ ! "$*" =~ "-X" ]]; then | ||
curl_command+=(-X GET) | ||
fi | ||
for arg in "${@}"; do | ||
curl_command+=("$arg") | ||
done | ||
"${curl_command[@]}" || { | ||
echo "ERROR: curl (${curl_command[*]})" >&2 | ||
return 1 | ||
} | ||
} | ||
|
||
responds_with () { | ||
local expected | ||
expected="$1" | ||
shift | ||
_curl "${@}" | grep "$expected" || { | ||
echo "ERROR: curl expected (${*}): $expected" >&2 | ||
return 1 | ||
} | ||
} | ||
|
||
responds_with \ | ||
"via: sample-filter" \ | ||
"http://localhost:8080" |