forked from hengyoush/kyanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: introduce a script to test flag
--comm
(hengyoush#222)
- Loading branch information
1 parent
f677d60
commit 537a08a
Showing
4 changed files
with
125 additions
and
45 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
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,27 @@ | ||
import http.server | ||
import ssl | ||
from socketserver import ThreadingMixIn | ||
|
||
# 创建自定义的 HTTP 服务器类,支持线程以处理多个连接 | ||
class ThreadedHTTPServer(ThreadingMixIn, http.server.HTTPServer): | ||
# 设置 allow_reuse_address 以支持长连接 | ||
allow_reuse_address = True | ||
|
||
class KeepAliveHandler(http.server.SimpleHTTPRequestHandler): | ||
# 设置响应头以启用长连接 | ||
|
||
# 重写 `do_GET` 方法处理 GET 请求 | ||
def do_GET(self): | ||
self.send_response(200) | ||
self.send_header("Content-type", "text/html") | ||
self.send_header("Connection", "keep-alive") | ||
self.send_header("Content-Length", str(len("Hello, this is an HTTP server with keep-alive support!"))) | ||
self.end_headers() | ||
self.wfile.write(b"Hello, this is an HTTP server with keep-alive support!") | ||
|
||
# 服务器地址和端口 | ||
server_address = ('localhost', 8080) | ||
httpd = ThreadedHTTPServer(server_address, KeepAliveHandler) | ||
|
||
print("HTTP server running on http://localhost:8080 with keep-alive support") | ||
httpd.serve_forever() |
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,39 @@ | ||
#!/usr/bin/env bash | ||
. $(dirname "$0")/common.sh | ||
set -ex | ||
|
||
CMD="$1" | ||
FILE_PREFIX="/tmp/kyanos" | ||
BEFORE_LNAME="${FILE_PREFIX}_filter_by_comm_before.log" | ||
AFTER_LNAME="${FILE_PREFIX}_filter_by_comm_after.log" | ||
|
||
function test_filter_by_server_comm() { | ||
# server start before kyanos | ||
timeout 40 python3 ./testdata/start_http_server.py & | ||
timeout 30 ${CMD} watch --debug-output http --comm python3 2>&1 | tee "${BEFORE_LNAME}" & | ||
sleep 2 | ||
timeout 25 ./testdata/https-request/https-request 'http://127.0.0.1:8080' 40 & | ||
sleep 10 | ||
wait | ||
|
||
cat "${BEFORE_LNAME}" | ||
cat "${BEFORE_LNAME}" | grep "Host: 127.0.0.1:8080" | grep "\\[side\\]=server" | ||
} | ||
|
||
# skip for https://github.com/hengyoush/kyanos/pull/222#issuecomment-2566106756 | ||
function test_filter_by_client_comm() { | ||
# client start after kyanos | ||
timeout 40 ${CMD} watch --debug-output http --comm https-request 2>&1 | tee "${AFTER_LNAME}" & | ||
sleep 10 | ||
timeout 30 ./testdata/https-request/https-request 'http://ipinfo.io' 40 & | ||
wait | ||
|
||
cat "${AFTER_LNAME}" | ||
cat "${AFTER_LNAME}" | grep "Host: ipinfo.io" | grep "\\[side\\]=client" | ||
} | ||
|
||
function main() { | ||
test_filter_by_server_comm | ||
} | ||
|
||
main |