perf: 重构优化路由性能,添加日志系统,优化大文件内存占用,加强输入验证及路径安全等
This commit is contained in:
+11
-8
@@ -2,6 +2,7 @@ import hono
|
||||
import net.http
|
||||
import os
|
||||
import time
|
||||
import strings
|
||||
|
||||
fn main() {
|
||||
println('=== 文件流式传输测试 ===')
|
||||
@@ -37,21 +38,23 @@ fn create_test_files() {
|
||||
println(' 创建小文件: test_small.txt (${small_content.len} bytes)')
|
||||
|
||||
// 创建中等文件 (1MB)
|
||||
mut medium_content := ''
|
||||
mut medium_content := strings.new_builder(1024 * 1024)
|
||||
for i in 0 .. 1000 {
|
||||
medium_content += 'This is line ${i:04d} with some content to make it longer.\n'
|
||||
medium_content.write_string('This is line ${i:04d} with some content to make it longer.\n')
|
||||
}
|
||||
os.write_file('test_medium.txt', medium_content) or { panic(err) }
|
||||
println(' 创建中等文件: test_medium.txt (${medium_content.len} bytes)')
|
||||
medium_str := medium_content.str()
|
||||
os.write_file('test_medium.txt', medium_str) or { panic(err) }
|
||||
println(' 创建中等文件: test_medium.txt (${medium_str.len} bytes)')
|
||||
|
||||
// 创建大文件 (模拟5MB)
|
||||
mut large_content := ''
|
||||
mut large_content := strings.new_builder(5 * 1024 * 1024)
|
||||
base_line := 'This is a long line of text that will be repeated many times to create a large file for testing streaming functionality. '
|
||||
for i in 0 .. 50000 { // 约5MB
|
||||
large_content += '${i:06d}: $base_line\n'
|
||||
large_content.write_string('${i:06d}: $base_line\n')
|
||||
}
|
||||
os.write_file('test_large.txt', large_content) or { panic(err) }
|
||||
println(' 创建大文件: test_large.txt (${large_content.len} bytes)')
|
||||
large_str := large_content.str()
|
||||
os.write_file('test_large.txt', large_str) or { panic(err) }
|
||||
println(' 创建大文件: test_large.txt (${large_str.len} bytes)')
|
||||
}
|
||||
|
||||
fn setup_test_routes(mut app hono.Hono) {
|
||||
|
||||
Reference in New Issue
Block a user