https://github.com/FusionAuth/java-http Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + By Plan + Enterprise + Teams + Compare all + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} FusionAuth / java-http Public * Notifications * Fork 0 * Star 33 A full featured, stand-alone, high-performance HTTP server and client written entirely in plain Java License Apache-2.0 license 33 stars 0 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights FusionAuth/java-http This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 2 branches 5 tags Code * Clone HTTPS GitHub CLI [https://github.com/F] Use Git or checkout with SVN using the web URL. [gh repo clone Fusion] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @voidmain voidmain * Added IPV6 check for binding the server socket to hopefully help wi... ... a379ab6 Oct 24, 2022 * Added IPV6 check for binding the server socket to hopefully help wi... ...th Docker * Bumped Savant plugins to version 2.0.0-RC.2 and update action to use the same version of the Savant runtime a379ab6 Git stats * 67 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows * Added IPV6 check for binding the server socket to hopefully help wi... Oct 24, 2022 src * Added IPV6 check for binding the server socket to hopefully help wi... Oct 24, 2022 .gitignore Initial commit Aug 29, 2022 LICENSE Initial commit Aug 29, 2022 README.md * Version bump for release Oct 19, 2022 build.savant * Added IPV6 check for binding the server socket to hopefully help wi... Oct 24, 2022 java-http.iml * Bug fixes Sep 30, 2022 java-http.ipr * Excluded performance tests from the main set because Github Actions... Oct 18, 2022 pom.xml * Added IPV6 check for binding the server socket to hopefully help wi... Oct 24, 2022 View code [ ] FusionAuth HTTP client and server Installation Examples Usages: TLS Performance Todos and Roadmap Server tasks Client tasks Helping out Building with Savant README.md FusionAuth HTTP client and server semver 2.0.0 compliant test NOTE: This project is in progress. The goal of this project is to build a full-featured HTTP server and client in plain Java without the use of any libraries. The client and server will use non-blocking NIO in order to provide the highest performance possible. Installation To add this library to your project, you can include this dependency in your Maven POM: io.fusionauth java-http 0.1.4 If you are using Gradle, you can add this to your build file: implementation 'io.fusionauth:java-http:0.1.4' If you are using Savant, you can add this to your build file: dependency(id: "io.fusionauth:java-http:0.1.4") Examples Usages: Creating a server is simple: import io.fusionauth.http.server.HTTPListenerConfiguration; import io.fusionauth.http.server.HTTPServer; import io.fusionauth.http.server.HTTPHandler; public class Example { public static void main(String... args) { HTTPHandler handler = (req, res) -> { // Handler code goes here }; HTTPServer server = new HTTPServer().withHandler(handler).withListener(new HTTPListenerConfiguration(4242)); server.start(); // Use server server.close(); } } Since the HTTPServer class implements java.io.Closeable, you can also use a try-resource block like this: import io.fusionauth.http.server.HTTPListenerConfiguration; import io.fusionauth.http.server.HTTPServer; import io.fusionauth.http.server.HTTPHandler; public class Example { public static void main(String... args) { HTTPHandler handler = (req, res) -> { // Handler code goes here }; try (HTTPServer server = new HTTPServer().withHandler(handler).withListener(new HTTPListenerConfiguration(4242))) { server.start(); // When this block exits, the server will be shutdown } } } You can also set various options on the server using the with methods on the class like this: import java.time.Duration; import io.fusionauth.http.server.HTTPListenerConfiguration; import io.fusionauth.http.server.HTTPServer; import io.fusionauth.http.server.HTTPHandler; public class Example { public static void main(String... args) { HTTPHandler handler = (req, res) -> { // Handler code goes here }; HTTPServer server = new HTTPServer().withHandler(handler) .withNumberOfWorkerThreads(42) .withShutdownDuration(Duration.ofSeconds(10L)) .withListener(new HTTPListenerConfiguration(4242)); server.start(); // Use server server.close(); } } TLS The HTTP server implements TLS 1.0-1.3 using the Java SSLEngine. To enable TLS for your server, you need to create an HTTPListenerConfiguration that includes a certificate and private key. Most production use-cases will use a proxy such as Apache, Nginx, ALBs, etc. In development, it is recommended that you set up self-signed certificates and load those into the HTTP server. To set up self-signed certificates on macOS, you can use the program mkcert. Here is an example: brew install mkcert mkcert -install mkdir -p ~/dev/certificates mkcert -cert-file ~/dev/certificates/example.org.pem -key-file ~/dev/certificates/example.org.key example.org Now you can load these into the HTTP server like this: import java.nio.file.Files; import java.nio.file.Paths; import java.time.Duration; import io.fusionauth.http.server.HTTPHandler; import io.fusionauth.http.server.HTTPServer; public class Example { private String certificate; private String privateKey; public static void main(String[] args) { String homeDir = System.getProperty("user.home"); certificate = Files.readString(Paths.get(homeDir + "/dev/certificates/example.org.pem")); privateKey = Files.readString(Paths.get(homeDir + "/dev/certificates/example.org.key")); HTTPHandler handler = (req, res) -> { // Handler code goes here }; HTTPServer server = new HTTPServer().withHandler(handler) .withListener(new HTTPListenerConfiguration(4242, certificate, privateKey)); // Use server server.close(); } } And finally, you'll need to add the domain name to your hosts file to ensure that the SNI lookup handles the certificate correctly. For this example, you would use this entry in the /etc/hosts file: 127.0.0.1 example.org Then you can open https://example.org in a browser or call it using an HTTP client (i.e. Insomnia, Postman, etc or in code). Performance A key component for this project is to have awesome performance. Here are some basic metrics using the FusionAuth load test suite against a simple application using the Prime Framework MVC. The controller does nothing except return a simple 200. Here are some simple comparisons between Tomcat, Netty, and java-http. The load test configuration is set to 10 clients with 500,000 requests each. The client is Restify which is a FusionAuth library that uses URLConnection under the hoods. All the servers were HTTP so that TLS would not introduce any additional latency. Here are the current test results: Server RPS Failures per second java-http 63,216 0 Tomcat 51,351 0.103 Netty 540 1.818 Netty and Tomcat both seem to suffer from buffering and connection issues at very high scale. Regardless of the configuration, both servers always begins to fail with connection timeout problems at scale. java-http does not have these issues because of the way it handles connections via the selector. Connections don't back up and client connection pools can always be re-used with Keep-Alive. The general requirements and roadmap are as follows: Todos and Roadmap Server tasks * [*] Basic HTTP 1.1 * [*] Support Keep-Alive * [*] Support Expect-Continue 100 * [*] Support chunked request * [*] Support chunked response * [*] Support streaming entity bodies (via chunking likely) * [*] Support compression * [*] Support cookies in request and response * [*] Clean up HTTPRequest * [*] Support form data * [*] Support multipart form data * [*] Support TLS * [ ] Support trailers * [ ] Support HTTP 2 Client tasks * [ ] Basic HTTP 1.1 * [ ] Support Keep-Alive * [ ] Support TLS * [ ] Support Expect-Continue 100 * [ ] Support chunked request and response * [ ] Support streaming entity bodies * [ ] Support form data * [ ] Support multipart form data * [ ] Support HTTP 2 Helping out We are looking for Java developers that are interested in helping us build the client and server. If you know a ton about networks and protocols and love writing clean, high-performance Java, contact us at dev@fusionauth.io. Building with Savant Note: This project uses the Savant build tool. To compile using Savant, follow these instructions: $ mkdir ~/savant $ cd ~/savant $ wget http://savant.inversoft.org/org/savantbuild/savant-core/1.0.0/savant-1.0.0.tar.gz $ tar xvfz savant-1.0.0.tar.gz $ ln -s ./savant-1.0.0 current $ export PATH=$PATH:~/savant/current/bin/ About A full featured, stand-alone, high-performance HTTP server and client written entirely in plain Java Topics java http http-client http-server java17 Resources Readme License Apache-2.0 license Stars 33 stars Watchers 8 watching Forks 0 forks Releases 5 tags Packages 0 No packages published Contributors 2 * @voidmain voidmain Brian Pontarelli * @robotdan robotdan Daniel DeGroff Languages * Java 100.0% Footer (c) 2022 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.