smart-http 1.0.15發布 輕量級的國產HTTP服務器
更新時間:2020-06-22 來源:電腦技巧自學網
smart-http 是一款采用 Java 語言編寫的 Http 服務器,有別于業界知名的 Web容器:Tomcat、Undertow,smart-http 并不支持 Servlet 規范,但對于 http 服務器所需的各項能力,它都具備。smart-http 天生就是異步非阻塞的 I/O 模型,因為其通信內核采用了 smart-socket。所以無論是性能還是穩定性,都是非常出色的。
更新內容
優化Http Request的流操作
修復長連接狀態下的個別字段未重置問題。
支持Http1.0協議的長連接。
增加畸形報文攻擊防范策略。
WebSocketResponse 新增 flush 接口。
升級 smart-socket 至 1.4.12。
快速體驗
在您的Maven工程中引入smart-http依賴。
<dependency>
<groupId>org.smartboot.http</groupId>
<artifactId>smart-http-server</artifactId>
<version>1.0.15</version></dependency>
拷貝以下代碼并啟動。
public class SimpleSmartHttp { public static void main(String[] args) {
HttpBootstrap bootstrap = new HttpBootstrap(); //http消息
bootstrap.pipeline().next(new HttpHandle() { public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
response.write("hello world".getBytes());
}
}); //websocket消息
bootstrap.wsPipeline().next(new WebSocketHandle() { public void doHandle(WebSocketRequest request, WebSocketResponse response) throws IOException {
response.sendTextMessage("hello world");
}
});
bootstrap.setPort(8080).start();
}
}
瀏覽器訪問:http://localhost:8080/ 或采用ws客戶端請求ws://127.0.0.1:8080
更多文檔請訪問:https://smartboot.gitee.io/book/smart-http/
點擊數: 160