33 个版本
0.5.47 | 2024 年 4 月 23 日 |
---|---|
0.5.46 | 2024 年 4 月 1 日 |
0.5.44 | 2024 年 3 月 31 日 |
0.4.91 | 2024 年 3 月 21 日 |
0.1.5 | 2024 年 3 月 17 日 |
#171 在 HTTP 服务器 中
595KB
349 行
考虑到性能、优化和使用便利性。
目前仅支持 C/C++/Rust 编程语言。
此库完全使用 tokio 从头构建。
基本 hello world 示例
基本的 hello world Html 实现
use rohanasan::{
rohanasan, send_http_response, serve, Request, DEFAULT_HTML_HEADER,
};
fn handle(req: Request) -> String {
send_http_response(DEFAULT_HTML_HEADER, "<h1>Hello!</h1>", req)
}
fn main() {
rohanasan! {
serve(8080, handle)
}
}
如何在您的项目中使用它?
- 打开您希望创建项目文件夹的父文件夹中的终端
- 运行
cargo install rohanasanpm
rohanasanpm new my_proj
cd
进入 my_projcargo run
运行您的项目。- 转到:
localhost:8080
。 - 享受使用罗哈纳桑!
如何运行示例?
git clone https://github.com/rohanasan/rohanasan-rs.git
cd rohanasan-rs
cd examples
cargo run --example standard
Discord 服务器链接
性能
机器规格
操作系统: Garuda Linux x86_64
笔记本电脑: 戴尔 Inspiron 5590
内核: 6.8.1-zen1-1-zen
模式: 图形用户界面模式(终端像窗口一样运行)
Shell: fish 3.7.0
终端: konsole 24.2.1
处理器: Intel(R) Core(TM) i3-10110U (4) @ 4.10 GHz
显卡: Intel UHD Graphics(CPU 本身)
内存: 11.47 GiB
运行测试所使用的命令: wrk -t 2 -c 100 https://127.0.0.1:8080
结果
线程统计 | 平均值 | 标准差 | 最大值 | +/- 标准差 |
---|---|---|---|---|
延迟 | 844.10us | 480.14us | 4.14ms | 64.85% |
每秒请求数 | 26.24k | 831.40 | 28.10k | 70.00% |
输出: 10.02 秒内完成 522523 个请求,读取 46.84MB
每秒请求数 52142.29
传输速率: 4.67MB
运行的程序: examples/hello_world.rs
当前功能
- 可以在指定的端口运行服务器
- 可以在 /static 下提供名为 static 的文件夹
- 可以将文件作为 http 响应发送
- 可以提供路径、方法和协议
待办
- 添加功能以更改公共文件夹的目录路径 ☑️ 完成!!!!
- 异步文件请求处理 ☑️ 完成!!!!
- 添加功能,让用户可以选择将 index.html 添加到静态文件夹 ☑️ 完成!!!!
- 添加功能:
request.post_request()
- 添加功能……目前这只是预 alpha 版本,我现在必须添加许多功能!
贡献
-
请支持 rohanasan: https://www.buymeacoffee.com/rohanvashisht
-
请 star rohanasan 的 github 仓库: https://github.com/rohanasan/rohanasan-rs
示例
- Hello world (Html 文件)
基本的 hello world Html 实现
use rohanasan::{
rohanasan, send_file, serve, Request, DEFAULT_HTML_HEADER,
};
fn handle(req: Request) -> String {
send_file(DEFAULT_HTML_HEADER, "./html/index.html", req)
}
fn main() {
rohanasan! {
serve(8080, handle)
}
}
注意事项
- 使用 rohanasan 宏不需要导入 tokio。
- 默认情况下,rohanasan 会在你运行服务器的同一目录中提供名为 static 的任何文件夹。
依赖项
~2.4–8.5MB
~58K SLoC