您现在的位置是:首页 > 文章详情

🎉smart-http v1.3.4 发布,对国外非法请求 Say NO!

日期:2023-10-19点击:224

1、smart-http 简介

smart-http 是一款可编程式 HTTP 应用微内核。它是目前市面上为数不多即能严格准守 RFC2616 规范,又兼顾卓越性能的 Http 服务器。

smart-http 建立在自研的通信框架 smart-socket 之上,使其有着纯正的国产化血统。该项目对标的是 nginx,高性能、轻量化是其追求和坚持的目标。

模块介绍

模块 说明 代码量
smart-http-common 基础通用模块,包括枚举、日志、工具类 2300+
smart-http-client HTTP Client 编解码和响应式编程设计 1400+
smart-http-server HTTP Server 和 WebSocket 的编解码和应用层接口设计 2800+
smart-http-restful 基于 smart-http-server 的简易版 MVC 模块(实验性 680
smart-http-restful-mybatis 类似 mybatis-spring(实验性 25
smart-http-test 单测模块 1600+

2、 版本更新

这是一个特别的版本,还是一个新的起点。

smart-http 一直以来都以「极简、易用、高性能」为设计理念,但凡跟这三点不相干的内容,我们从来不会去 care。

但是,随着近期观察到我部署在互联网上的服务频繁受到骚扰,让我意识到「安全」,也是 smart-http 应该去关注的方向。

以下是检测到来自世界各地的非正常访问:

  • 来自美国的流量,访问不存在资源。

  • 来自美国的流量,非正常 HTTP 报文

  • 来自越南的流量。

  • 来自荷兰的流量

除了非法请求,还有一些会长期占用 TCP 连接资源的情况。目前我的站点提供的只是一些简单的服务,此类流量还没有造成负面影响。但对于这种不礼貌的行径,我觉得作为一款专业的 http 服务,还是能够做一些事情的。

所以,我们决定在 smart-http 搭建一套 waf 的能力。主动防御一切非法请求,并给予以下反馈:

来自东方的神秘力量正在守护这片区域

这个版本主要搭建了 waf 的基础骨架,并实现了对于 Method、URI 的检测,后续我们再不断完善 waf 的检测规则和覆盖范围。

Maven

 <dependency>     <groupId>org.smartboot.http</groupId>     <artifactId>smart-http-server</artifactId>     <version>1.3.4</version> </dependency> <dependency>     <groupId>org.smartboot.http</groupId>     <artifactId>smart-http-client</artifactId>     <version>1.3.4</version> </dependency> 

本次更新内容

  1. restful 模块新增 commons-fileupload 的适配,提供文件上传的处理能力。

  2. 新增 waf 模块,提升 HTTP 服务安全性。

3、快速上手

3.1 HTTP 服务端

 public class SimpleSmartHttp {     public static void main(String[] args) {         HttpBootstrap bootstrap = new HttpBootstrap();         bootstrap.httpHandler(new HttpServerHandler() {             @Override             public void handle(HttpRequest request, HttpResponse response) throws IOException {                 response.write("hello smart-http<br/>".getBytes());             }         }).setPort(8080).start();     } } 

3.2 WebSocket 服务端

 public class WebSocketDemo {     public static void main(String[] args) {         //1. 实例化路由Handle         WebSocketRouteHandler routeHandle = new WebSocketRouteHandler();         //2. 指定路由规则以及请求的处理实现         routeHandle.route("/"new WebSocketDefaultHandler() {             @Override             public void handleTextMessage(WebSocketRequest request, WebSocketResponse response, String data) {                 response.sendTextMessage("接受到客户端消息:" + data);             }         });         // 3. 启动服务         HttpBootstrap bootstrap = new HttpBootstrap();         bootstrap.webSocketHandler(routeHandle);         bootstrap.start();     } } 

3.3 Http 客户端

 public class HttpGetDemo {     public static void main(String[] args) {         HttpClient httpClient = new HttpClient("www.baidu.com"80);         httpClient.get("/").header().keepalive(false).done()                 .onSuccess(response -> System.out.println(response.body()))                 .onFailure(Throwable::printStackTrace)                 .done();     } } 

3.4 Restful

 <dependency>     <groupId>org.smartboot.http</groupId>     <artifactId>smart-http-restful</artifactId>     <version>${smarthttp.version}</version> </dependency> 
 @Controller public class RestfulDemo {     @RequestMapping(value = "/hello", method = RequestMethod.GET)     public String helloworld() {         return "hello world";     }     public static void main(String[] args) throws Exception {         RestfulBootstrap bootstrap = RestfulBootstrap.getInstance().controller(RestfulDemo.class);         bootstrap.bootstrap().setPort(8080).start();     } } 

smartboot 开源组织,一个容易被误认为是在 “重复造轮子” 的低调组织。曾获得 2020 年度 OSC 中国开源项目「优秀 Gitee 组织 」荣誉。

该组织内的明星项目包括:

  • smart-socket
    历时 5 年精炼出 2 千多行代码,轻松实现百万级长连接的 AIO 通信框架。

  • smart-http
    基于 smart-socket 实现的 HTTP/1.1 web 服务。

  • smart-servlet
    基于 smart-http 实现的 Servlet 3.1 容器服务。

  • smart-mqtt
    基于 smart-socket 实现的 MQTT 3.1.1/5.0 Broker&Client 服务。

  • smart-flow
    一款具备可观测性的轻量级业务编排框架。

组织地址:https://smartboot.tech/
代码仓库:https://gitee.com/smartboot

原文链接:https://www.oschina.net/news/262427/smart-http-1-3-4-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章