Re: HTTP request handler / middleware SRFI
Peter Bex 05 Apr 2019 14:02 UTC
On Fri, Apr 05, 2019 at 02:04:59AM -1000, Shiro Kawai wrote:
> It could be useful in a long run, but I wonder if we need to formalize the
> API as srfi at this point. We can start from a portable library and use it
> in many projects on multiple Scheme implementations until it become mature,
> to see how it fits well in Scheme universe. It's not tool late to make a
> srfi after seeing the success of such library---after all, if we have one
> de-facto library, there's no need to agree on API among multiple
> implementations.
>
> If we find a lower-level abstraction required to write a portable
> middleware along the way, then we can make srfi for that specific area.
>
> Or, do you already have an existing library in your mind to start with?
> Then I'll port it to Gauche and see how it goes!
I'd suggest you take a look at Intarweb [1]. This is a library for
parsing and generating HTTP/1.x requests and responses once, so that you
don't end up implementing the same stupid parsers (with variances) all
over the place like what happens in many languages. The latter is
a web server built on top of it
I'm not 100% happy with the way it works (it feels a bit clunky and
arbitrary), so please, feel free to improve on it. It can handle
web sockets, see the websocket egg[2], but it does not handle HTTP/2.0
or HTTP/3.0; changing that would probably require a redesign.
There's a web server called Spiffy [3] that's built on top of Intarweb
and a client called http-client [4], which is also built on top.
The code is currently somewhat CHICKEN-specific but most of the parsing
stuff can be done in pure Scheme.
[1] docs at https://wiki.call-cc.org/eggref/5/intarweb
code at https://code.more-magic.net/intarweb/
[2] docs at https://wiki.call-cc.org/eggref/4/websockets
code at https://bitbucket.org/thomashintz/websockets
(this has not been ported to CHICKEN 5 yet)
[3] docs at https://wiki.call-cc.org/eggref/5/spiffy
code at https://code.more-magic.net/spiffy/
[4] docs at https://wiki.call-cc.org/eggref/5/http-client
code at https://code.more-magic.net/http-client/
Cheers,
Peter