// 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();
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
An embedded HTTP server written by a pure Java.
License
tuuzed/microhttpd
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
An embedded HTTP server written by a pure Java.
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published