hyper icon indicating copy to clipboard operation
hyper copied to clipboard

Support non-UTF8 requests

Open owickstrom opened this issue 8 years ago • 6 comments

The String instance of readBody in the Node server assumes UTF8, it should check Content-Type header.

owickstrom avatar Dec 20 '16 06:12 owickstrom

It should also support binary data, and streaming, and MIME in general. I think the fundep on ReadableBody needs to be removed for this.

no-longer-on-githu-b avatar May 15 '17 12:05 no-longer-on-githu-b

@rightfold Agreed. Not sure where you mean the functional dependency is, though?

owickstrom avatar May 16 '17 14:05 owickstrom

Fundep from body reader type to body type.

class ReadableBody req m b | req -> b

no-longer-on-githu-b avatar May 16 '17 14:05 no-longer-on-githu-b

Yes, you're absolutely right. I'll try loosening that, and adding some more instances.

Regarding binary, I could add an instance for getting an Aff e Buffer, as with String.

For streaming, exposing the request's Stream will do for now. In the spirit of Hyper, the stream should only be allowed to be read once (it cannot be read twice, but you could get a compile-time error if you try). That would probably require some other design than just handing back the Readable stream -- like hiding the streaming within the indexed monad and track whether you've been streaming or not. Any thoughts?

owickstrom avatar May 17 '17 07:05 owickstrom

Well, where "read once" means "read until exhausted." Stream has a godforsaken Node.js-style callback API, so you can't really demand to read it twice, right? It'll just stop calling you when there's nothing to read.

no-longer-on-githu-b avatar May 17 '17 12:05 no-longer-on-githu-b

Regarding this issue, it should only be about the String instance checking the Content-Type header and using that when doing toString on the buffer. Buffers in general, and streaming, are separate issues, but we already have the PRs open. :+1:

owickstrom avatar May 18 '17 08:05 owickstrom