{"id":16701194,"url":"https://github.com/oliver-loeffler/niohttp","last_synced_at":"2025-07-04T08:04:23.435Z","repository":{"id":89874364,"uuid":"83896633","full_name":"Oliver-Loeffler/NIOHttp","owner":"Oliver-Loeffler","description":"Building HTTP requests and responses using Java NIO/NIO2","archived":false,"fork":false,"pushed_at":"2017-04-27T07:35:03.000Z","size":105,"stargazers_count":2,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-04T08:04:20.444Z","etag":null,"topics":["http","java-nio"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Oliver-Loeffler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-04T13:49:49.000Z","updated_at":"2024-06-07T18:35:19.000Z","dependencies_parsed_at":"2023-07-04T14:33:30.012Z","dependency_job_id":null,"html_url":"https://github.com/Oliver-Loeffler/NIOHttp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Oliver-Loeffler/NIOHttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oliver-Loeffler%2FNIOHttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oliver-Loeffler%2FNIOHttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oliver-Loeffler%2FNIOHttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oliver-Loeffler%2FNIOHttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Oliver-Loeffler","download_url":"https://codeload.github.com/Oliver-Loeffler/NIOHttp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oliver-Loeffler%2FNIOHttp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263472275,"owners_count":23471811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","java-nio"],"created_at":"2024-10-12T18:43:07.217Z","updated_at":"2025-07-04T08:04:23.409Z","avatar_url":"https://github.com/Oliver-Loeffler.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NIOHttp\n\n[![Build Status](https://travis-ci.org/Oliver-Loeffler/NIOHttp.svg?branch=master)](https://travis-ci.org/Oliver-Loeffler/NIOHttp)  \n\nReading and writing HTTP request and response objects from and to  ``java.nio.channels`` .\n\n:warning: *This project has exploratory character and is in a very early stage of development.* \n\n## Goals\n\n * Create a library/toolkit to write and read HTTP requests to and from ``java.nio.channels`` (Java's non-blocking IO)\n * Explore ``java.util.concurrentjava.util.concurrent`` API\n * Do not use external frameworks, integrate HTTP protocol and  ``java.nio.channels``  using JDK 1.8+.\n\n### Boundary Conditions\n\n * zero external dependencies beside standard JDK except for unit \u0026 integration testing and build automation\n\n\n## Idea\n\nFirst one need to connect a **SocketStream** to a URL such as http://www.raumzeitfalle.de/.\n\n```java \n \n URL url = new URL(\"http://www.raumzeitfalle.de/\");\n InetSocketAddress address = new InetSocketAddress(url.getHost(), url.getDefaultPort());\n SocketChannel socketChannel = SocketChannel.open(address);\n\n```\nThe server won't respond unless a request is sent (for example a GET request).\n```java\n\n  writeGetRequestTo(socketChannel);\n  \n```\nEven with bad requests server will respond, however, this may take time and response time is different.\nHere the static **HttpResponseReader.fromChannel(...)** method provides a **FutureTask\u003c Void \u003e** which can be executed by an **ExecutorService**. To collect the result, a **Consumer\u003c HttpResponse \u003e** must be provided.\n(https://github.com/Oliver-Loeffler/NIOHttp/blob/master/src/main/java/net/raumzeitfalle/niohttp/playground/FutureDemo.java)\n\n```java\n\n FutureTask\u003cVoid\u003e futureTask = HttpResponseReader\n \t\t\t\t.fromChannel(socketChannel,r -\u003e System.out.println(r.responseHeader());\n \t\t\n ExecutorService executor = Executors.newFixedThreadPool(1);\n executor.submit(futureTask);\n\n```\nFurthermore **HttpResponseReader.fromChannel(...)** returns a **Stream** of HttpResponse objects\n(https://github.com/Oliver-Loeffler/NIOHttp/blob/master/src/main/java/net/raumzeitfalle/niohttp/playground/StreamDemo.java)\n\n```java\n\nStream\u003cHttpResponse\u003e responseStream = HttpResponseReader.fromChannel(socketChannel); \nresponseStream.findFirst().ifPresent(consumer);\n\n```\nThis would enable (given appropriate HttpResponse capabilities), interesting ways of working with HttpResponses. \n\n```java\n\nHttpResponseReader.fromChannel(socketChannel)\n\t    .filter( r -\u003e r.isNotBadRequest() )\n\t    .findFirst().ifPresent(consumer);\n\t    \n```\n\nThe current implementation is not yet fully functional here, as the **HttpResponseReader** only reads exactly one message from a channel. The response reading process has to be extended for continuous reading so that **HttpResponse** streaming will work.\n\n## Resources\n\n* HTTP Working Group: http://httpwg.org\n\n### The HTTP/1.1 Protocol \n\n* Introduction for RFC7230: http://httpwg.org/specs/rfc7230.html#introduction\n* Uniform Resource Identifier (URI) in HTTP: http://httpwg.org/specs/rfc7230.html#uri\n* Message format: http://httpwg.org/specs/rfc7230.html#http.message\n* Semantics and Content: http://httpwg.org/specs/rfc7231.html#top\n * Request Methods http://httpwg.org/specs/rfc7231.html#methods\n * Request Header fields: http://httpwg.org/specs/rfc7231.html#request.header.fields\n * Response Status Codes: http://httpwg.org/specs/rfc7231.html#status.codes\n * Response Header Fields: http://httpwg.org/specs/rfc7231.html#response.header.fields\n* IANA Status code assignments: http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml\n\n### HTTP/2 Protocol\n\n* Starting a HTTP/2 connection: http://httpwg.org/specs/rfc7540.html#starting\n* The protocol: http://httpwg.org/specs/rfc7540.html\n* HTTP/2 Message Exchanging: http://httpwg.org/specs/rfc7540.html#HTTPLayer\n\n### HTTP over TLS (transport layer security)\n\n * https://tools.ietf.org/html/rfc2818#section-2\n\n### Java non-blocking IO (NIO and NIO2) and Networking\n\n* Java API\n * https://docs.oracle.com/javase/tutorial/\n * Java NIO channels: http://docs.oracle.com/javase/8/docs/api/java/nio/channels/package-summary.html\n \n* Guides \u0026 Tutorials, Inspiration\n * NIO2: http://www.ibm.com/developerworks/java/library/j-nio2-1/index.html\n * NIO2 Async FileChannel: http://www.baeldung.com/java-nio2-async-file-channel\n * Jenkov: http://tutorials.jenkov.com/java-nio/index.html\n * NIO Selectors: http://www.baeldung.com/java-nio-selector\n * Apache HttpClient: http://www.baeldung.com/httpasyncclient-tutorial\n * Javaworld on NIO/NIO2: http://www.javaworld.com/article/2078654/core-java/java-se-five-ways-to-maximize-java-nio-and-nio-2.html\n * Java2s on non-blocking async IO: http://www.java2s.com/Tutorials/Java/Java_Network/0080__Java_Network_Asynchronous_Socket_Channels.htm\n \n### Other helpful references\n\n * As RFC7230 uses the term ABNF, here the explanation: https://en.wikipedia.org/wiki/Augmented_Backus–Naur_form\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foliver-loeffler%2Fniohttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foliver-loeffler%2Fniohttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foliver-loeffler%2Fniohttp/lists"}