Are there Kotlin implementations of "Network protocols, sans I/O"?

Network protocols, sans I/O is a strategy for implementing networking protocols without coupling the implementation to I/O and thus enabling reuse of the networking protocol implementation in any I/O context.

The strategy stems from the Python world, but I’m looking for equivalents in Kotlin (or maybe Java), specifically an implementation for HTTP/1.1 (which would be equivalent to h11).

Does anyone know of any equivalents?

I am not sure I understand you correctly, but it seems you are talking about common IO abstraction. On JVM you can use java.nio. It has a well-developed abstraction layer (Channels. Buffers, etc). For multiplatform there was some effort in GitHub - Kotlin/kotlinx-io: Kotlin multiplatform I/O library, but sadly it is frozen for now because of lack of manpower. I currently use ktor/ktor-io at main · ktorio/ktor · GitHub with the aim to move to kotlinx-io in future.

Thanks @darksnake, but I’m looking for the opposite of what you’re pointing me to.
You’re pointing me to I/O related code, but I’m looking for network protocol implementations that are de-coupled from I/O.

Another way of putting it is:
I’m looking for the ability to deserialize and serialize HTTP/1.1 requests and responses. Being able to manipulate the HTTP data structures (e.g. add in a header) between deserializing and serializing, is also necessary.
E.g. I’d like to be able to implement a HTTP proxy of sorts.

Well, there are tons of that in

Thank you, (e.g. looks like it might be on the right track, but I’m still not sure it’s exactly what I’m after.

Hopefully this concrete pseudocode/example will make it crystal clear:

I need to be able to take a raw HTTP request like this:

GET /hello/world HTTP/1.1
user-agent: curl/7.68.0
accept: */*

…parse it into some data structure that can be inspected and manipulated, e.g.:

request.method == "GET" == ""

request.headers.set('Authorization', 'abc')

…serialize it back into the raw HTTP request it started as.

I need to also be able to do this for HTTP responses as well.

Something subtle I glossed over, but which the Python h11 library provides (and which I require) is the ability to know when a request/response has been completely received/parsed. E.g. If I’m reading a request/response from a TCP socket, I need to know when to stop reading from the socket (i.e. when I have the whole request/response).
This is copied from the README of the h11 GitHub project:

At a high level, working with h11 goes like this:

  1. First, create an h11.Connection object to track the state of a single HTTP/1.1 connection.
  2. When you read data off the network, pass it to conn.receive_data(...) ; you’ll get back a list of objects representing high-level HTTP “events”.
  3. When you want to send a high-level HTTP event, create the corresponding “event” object and pass it to conn.send(...) ; this will give you back some bytes that you can then push out through the network.

For example, a client might instantiate and then send a h11.Request object, then zero or more h11.Data objects for the request body (e.g., if this is a POST), and then a h11.EndOfMessage to indicate the end of the message. Then the server would then send back a h11.Response , some h11.Data , and its own h11.EndOfMessage . If either side violates the protocol, you’ll get a h11.ProtocolError exception.

From the classes I’ve seen, they seem to be coupled to the notion of sending/receiving requests/responses (to get objects of the classes) or to manually create the objects (rather than them being created from parsing raw HTTP requests/responses).