chibi.net.http-server config example

31 views
Skip to first unread message

*...@speechcode.com

unread,
Nov 18, 2021, 12:51:32 AM11/18/21
to chibi-scheme

I'm trying to figure out how to use a config file to set up (chibi net http-server), but I haven't been able to find an example. Does anyone have a simple one, e.g. one that serves a static directory as well as a POST handler?

Thanks.

*...@speechcode.com

unread,
Nov 18, 2021, 12:54:19 AM11/18/21
to chibi-scheme
P.S.: I see the example at the top of lib/chibi/net/http-server.scm, but that doesn't use the config infrastructure, which seems to be the recommended way to set up the server.

Alex Shinn

unread,
Nov 18, 2021, 1:13:40 AM11/18/21
to chibi-...@googlegroups.com
Here's one example:

https://github.com/ashinn/snow-fort/blob/master/config.scm

There's also the example at the bottom of http-server.scm:

chibi-scheme -Rchibi.net.http-config-server -- [<cfg-file-or-directory>]

with no config it's useful for just serving a file browser.

--
Alex

On Thu, Nov 18, 2021 at 2:54 PM *...@speechcode.com <*@speechcode.com> wrote:
>
> P.S.: I see the example at the top of lib/chibi/net/http-server.scm, but that doesn't use the config infrastructure, which seems to be the recommended way to set up the server.
>
> --
> You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/eb0aed58-348b-4804-acd1-a3853e073867n%40googlegroups.com.

Arthur A. Gleckler

unread,
Nov 18, 2021, 1:16:04 AM11/18/21
to chibi-...@googlegroups.com
On Wed, Nov 17, 2021 at 10:13 PM Alex Shinn <alex...@gmail.com> wrote:
Thank you!  I just found that one, too — after I sent my messages, of course.  I'm working on a config inspired by it now. 
 
There's also the example at the bottom of http-server.scm:

chibi-scheme -Rchibi.net.http-config-server -- [<cfg-file-or-directory>]

with no config it's useful for just serving a file browser.

Yes, I've been using that for purely static servers. 

Arthur A. Gleckler

unread,
Nov 18, 2021, 1:34:54 AM11/18/21
to chibi-...@googlegroups.com
I've got it working, but the process exits after handling just a few requests.  I see this comment in servlet-run in servlet.scm:

;; A servlet handler has been set, so we're in a persistent server.

Is it possible that the server is exiting because it's in some sort of non-persistent mode, as perhaps hinted at by this comment?

Alex Shinn

unread,
Nov 18, 2021, 1:38:23 AM11/18/21
to chibi-...@googlegroups.com
Ah, a long-standing bug, presumably in the thread scheduler :(
I actually run snow-fort in a while loop:

while true; do chibi-scheme -Rchibi.net.http-server --
snow-fort/config.scm; done

I'll bump the priority into looking into this now that I'm reminded.

FYI, the most important tip for testing a servlet without starting a
server is to run in CGI mode:

REQUEST_URI='http://mysite.com/myservlet.scm' chibi-scheme myservlet.scm

--
Alex
> --
> You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CALnw4LK5k-2LU6zwmSg9%2BnxLHH%3DU3peK3_jqs9n5QGZoySLLTA%40mail.gmail.com.

Arthur A. Gleckler

unread,
Nov 18, 2021, 1:58:39 AM11/18/21
to chibi-...@googlegroups.com
On Wed, Nov 17, 2021 at 10:38 PM Alex Shinn <alex...@gmail.com> wrote:
Ah, a long-standing bug, presumably in the thread scheduler :(

Ha!
 
I actually run snow-fort in a while loop:

while true; do chibi-scheme -Rchibi.net.http-server --
snow-fort/config.scm; done

I'll bump the priority into looking into this now that I'm reminded. 

Thank you. 

Alex Shinn

unread,
Nov 18, 2021, 8:53:57 PM11/18/21
to chibi-...@googlegroups.com
Thanks Arthur for pushing me to look into this and sharing your example offline.
Especially the strace made the root cause obvious - we're getting a SIGPIPE,
when the server writes to a client which has already closed its connection.
[For some reason this only happens once or twice a week on snow-fort.org,
but happened reliably in your case.]

Anyway, I pushed the trivial fix of ignoring SIGPIPE when running an
http server.

--
Alex
> --
> You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CALnw4LKOjxJM9-qYh_%3DNj1a9PftXcF7d-PcmixiL1YwVTikz-g%40mail.gmail.com.

Arthur A. Gleckler

unread,
Nov 18, 2021, 9:21:56 PM11/18/21
to chibi-...@googlegroups.com
On Thu, Nov 18, 2021 at 5:53 PM Alex Shinn <alex...@gmail.com> wrote:
 
Anyway, I pushed the trivial fix of ignoring SIGPIPE when running an
http server. 

Excellent.  It works for me.  I'm glad that it wasn't a threading bug.  Those can be tough to catch. 

Arthur A. Gleckler

unread,
Nov 19, 2021, 1:20:12 AM11/19/21
to chibi-...@googlegroups.com
On Thu, Nov 18, 2021 at 6:21 PM Arthur A. Gleckler <a...@speechcode.com> wrote:
 
Excellent.  It works for me.  I'm glad that it wasn't a threading bug.  Those can be tough to catch. 

I figured out the reason for the client disconnects: the server was sending the wrong Content-Type in many cases. On HTTP/1.1 connections when more than one resource was being delivered, that made the client (at least Google Chrome) hiccup. I just sent a pull request that fixes that for many file extensions. It might be better not to have a default MIME type, but I didn't make that change.

The server is working beautifully now! 

Alex Shinn

unread,
Nov 19, 2021, 2:18:07 AM11/19/21
to chibi-...@googlegroups.com
Thanks! Patch applied.
> --
> You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CALnw4L%2Bu4UVkrOaGkso6OMfR2efAyCfBhvcWRut6Q_VvqCV9-Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages