smart-http 1.0.11 发布,7 行代码便可运行的 HTTP 服务器

smart-http 是一款比较简易的 http服务器,其通信内核采用了异步非阻塞通信框架 smart-socket。

更新内容

  1. 升级smart-socket至最新版:1.4.5。

  2. 优化Http协议解析算法以获得更好的性能表现(依旧模仿nginx解码思路)。

  3. 提供对HEAD请求的支持。
  4. 节省解码期间不必要的内存开销。
  5. HttpRequest新增接口:getRemoteAddr、getRemoteHost。
  6. 代码重构,消除一些不合理的设计。

快速体验

  1. 在您的Maven工程中引入smart-http依赖。
    <dependency>
        <groupId>org.smartboot.http</groupId>
        <artifactId>smart-http-server</artifactId>
        <version>1.0.11</version>
    </dependency>
  2. 拷贝以下代码并启动。
    public class SimpleSmartHttp {
        public static void main(String[] args) {
            HttpBootstrap bootstrap = new HttpBootstrap();
            bootstrap.pipeline().next(new HttpHandle() {
                public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
                    response.write("hello world".getBytes());
                }
            });
            bootstrap.setPort(8080).start();
        }
    }
  3. 浏览器访问:http://localhost:8080/

最后

smart-http还处于起步阶段,只要你足够优秀便可引导它的发展路线,感兴趣的欢迎入坑。

猜你喜欢

转载自www.oschina.net/news/111379/smart-http-1-0-11-released
今日推荐