内容简介:这次的版本具体有这些更新:1.简化文件上传接口的使用,使用示例:
cinatra 本次更新主要侧重于简化接口使用,增加一些功能,修复一下bug。这仍然是一个预发布版本,但强烈推荐大家试用。
这次的版本具体有这些更新:
1.简化文件上传接口的使用,使用示例:
//http upload(multipart)
server.set_http_handler<GET, POST>("/upload_multipart", [](request& req, response& res) {
assert(req.get_content_type() == content_type::multipart);
auto text = req.get_query_value("text");
std::cout<<text<<std::endl;
auto& files = req.get_upload_files();
for (auto& file : files) {
std::cout << file.get_file_path() << " " << file.get_file_size() << std::endl;
}
res.set_status_and_content(status_type::ok, "multipart finished");
});
//http upload(octet-stream)
server.set_http_handler<GET, POST>("/upload_octet_stream", [](request& req, response& res) {
assert(req.get_content_type() == content_type::octet_stream);
auto& files = req.get_upload_files();
for (auto& file : files) {
std::cout << file.get_file_path() << " " << file.get_file_size() << std::endl;
}
res.set_status_and_content(status_type::ok, "octet-stream finished");
});
非常简洁,用户直接获取上传的文件即可,框架负责处理文件上传的细节。
2.简化文件下载功能
框架内置chunked文件下载功能,只要输入文件路径就可以实现下载:
http://127.0.0.1:8080/assets/show.jpg
更棒的是文件下载支持断点续传,这对大文件下载很方便。
3.简化websocket接口的使用
server.set_http_handler<GET, POST>("/ws", [](request& req, response& res) {
assert(req.get_content_type() == content_type::websocket);
req.on(ws_open, [](request& req){
std::cout << "websocket start" << std::endl;
});
req.on(ws_message, [](request& req) {
auto part_data = req.get_part_data();
//echo
std::string str = std::string(part_data.data(), part_data.length());
req.get_conn()->send_ws_string(std::move(str));
std::cout << part_data.data() << std::endl;
});
req.on(ws_close, [](request& req) {
std::cout << "websocket close" << std::endl;
});
req.on(ws_error, [](request& req) {
std::cout << "websocket error" << std::endl;
});
});
用户只需要在各自的事件响应函数里写逻辑即可,非常方便。
4.提供了一些更便利的render html接口
server.set_http_handler<GET, POST>("/string", [](request& req, response& res) {
res.render_string("OK");
},enable_cache{false});
server.set_http_handler<GET, POST>("/404", [](request& req, response& res) {
res.render_404();
},enable_cache{false});
server.set_http_handler<GET, POST>("/404_custom", [](request& req, response& res) {
res.render_404("./404.html");
},enable_cache{false});
5.修复了一些bug
- 修复了和nginx结合的时候cookie的一个bug
- 修复了multipart同时有文件和键值对时忽略了键值对的bug;
- 修复了multipart传多个文件时丢失header的bug;
- 修复了url请求不支持中文的bug;
欢迎大家试用并提出宝贵的建议和意见,让cinatra越来越完善.
Hope you can enjoy cinatra!
Post Views: 47
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Milvus 新版本 v0.10.5 发布
- 新版本来了! Milvus v1.1 发布!
- SparkyLinux新版本发布: SparkyLinux 5.6
- TarsPHP 新版本发布,支持 Protobuf 协议
- tiny-site 新版本发布
- AnyEiP.Press 新版发布,增加 CMDB 模块
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Go Web编程
谢孟军 / 电子工业出版社 / 2013-6-1 / 65.00元
《Go Web编程》介绍如何用Go语言进行Web应用的开发,将Go语言的特性与Web开发实战组合到一起,帮读者成功地构建跨平台的应用程序,节省Go语言开发Web的宝贵时间。有了这些针对真实问题的解决方案放在手边,大多数编程难题都会迎刃而解。 在《Go Web编程》中,读者可以更加方便地找到各种编程问题的解决方案,内容涵盖文本处理、表单处理、Session管理、数据库交互、加/解密、国际化和标......一起来看看 《Go Web编程》 这本书的介绍吧!