Draft: zio-http server interpreter#1150
Conversation
| case RawBodyType.ByteArrayBody => | ||
| request.data.content match { | ||
| case HttpContent.Complete(data) => Task.succeed(data.getBytes()) | ||
| case HttpContent.Chunked(data) => data.fold("")(_ + _).map(_.getBytes) |
There was a problem hiding this comment.
we shouldn't go through a String to get the bytes - as conversions (due to charsets etc) might malform the data. Maybe there's a way to concatenate byte chunks?
There was a problem hiding this comment.
Yes, this is wrong. Will correct once we have a Stream of bytes :)
| case HttpContent.Complete(data) => Task.succeed(data.getBytes()) | ||
| case HttpContent.Chunked(data) => data.fold("")(_ + _).map(_.getBytes) | ||
| } | ||
| case RawBodyType.ByteBufferBody => ??? |
There was a problem hiding this comment.
this & the next can be can typically implemented the same as getting a byte array
There was a problem hiding this comment.
Yes, we need HttpContent to support a stream of bytes
| case HttpContent.Chunked(data) => data.transduce(toBytes(StandardCharsets.UTF_8)) | ||
| } | ||
|
|
||
| def toStream(): streams.BinaryStream = stream.asInstanceOf[streams.BinaryStream] //TODO: this is weird we need a aggressive type cast |
There was a problem hiding this comment.
maybe if you type streams as : ZioStreams type inference will work? It's sometimes tricky with path-dependent types
| private def sttpToZHttpHeader(header: SttpHeader): ZHttpHeader = | ||
| ZHttpHeader(header.name, header.value) | ||
|
|
||
| def convert[I, O, R](route: Endpoint[I, Throwable, O, ZioStreams])(logic: I => RIO[R, O]): Http[R, Throwable] = { |
There was a problem hiding this comment.
maybe we can call toHttp? that would follow the convention in other interpreters
There was a problem hiding this comment.
Yes, also planning to support multiple endpoints in one go.
|
Thanks, looks promising! :) |
|
This should work with |
|
Could, I'll leave that up for later. Focus is first to have a module. I think the biggest thing to fix is that |
This is an initial attempt, but has a lot of todo's plus:
This is first sketch, I'm not an expert on websockets and ztapir. If someone can jump on the latter on a follow up PR, that would be great.