Metrics
0
Watch 35 Star 89 Fork 22

tuuzed / microhttpdJavaApache-2.0

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
一个纯Java编写的可嵌入的HTTP服务器 spread retract

https://git.oschina.net/tuuzed/microhttpd

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

MicroHTTPd

一个纯Java实现的轻量极的可嵌入的Http服务器。

简单使用

// MicroHTTPDSample.java
public class MicroHTTPDSample {

    public static void main(String[] args) {
        RouteHttpRequestDispatcher dispatcher = new RouteHttpRequestDispatcher()
                .addHandler(Pattern.compile("^/req$"), req -> {
                    return HttpResponses.text(req.toString());
                })
                .addHandler(Pattern.compile("^/$"), req -> {
                    return HttpResponses.text("hello every one");
                })
                .addHandler(Pattern.compile("^/mimetypes/*$"), req -> {
                    URL resource = MicroHTTPD.class.getResource("/mimetypes.txt");
                    File file = new File(resource.getFile());
                    return HttpResponses.file(file);
                })
                .addHandler(Pattern.compile("^/redirect/*$"), req -> {
                    return HttpResponses.redirect_301("//localhost:8000");
                })
                .addHandler(Pattern.compile("^/redirect2/*$"), req -> {
                    return HttpResponses.redirect_301("/mimetypes");
                });
        MicroHTTPD.builder()
                .addHttpRequestDispatcher(dispatcher)
                .useStaticFileHttpRequestDispatcher("/static/", new File("C:\\"))
                .setTimeout(1000, TimeUnit.MILLISECONDS)
                .build()
                .start();
    }
}
Java
1
https://gitee.com/tuuzed/MicroHTTPd.git
git@gitee.com:tuuzed/MicroHTTPd.git

Help Search