fukamachi / clack

Web server abstraction layer for Common Lisp
MIT License
1.04k stars 86 forks source link

Backend protocol clarifications #176

Closed zellerin closed 2 years ago

zellerin commented 2 years ago

Based on If you'd like to add a new web server, look into src/handler/ directory of the Clack repository. note in https://fukamachi.hashnode.dev/how-to-build-a-web-app-with-clack-and-lack-1, I tried to write backend for http2 server.

It works on the trivial "hello world" example, however, some points are not clear to me:

Incidentally, I looked at the writer-stream from lack utils and it seems to implement finishing by closing the output; this looks to me as a different action (I may want to finish output many times, but close only once, and finishing should wait for confirmation)

fukamachi commented 2 years ago

Thank you for asking, and sorry for the delay.

  • When you say "string", is some particular encoding specified? fcgi server uses :UTF, hunchentoot its default encoding. As an application writer I would want same behaviour everywhere, and as a backend writer... well.

It's up to the Lisp implementation setting (In SBCL, external-format). You can also pass byte vectors as binary data when you want to use other encodings explicitly.

  • Your delayed response example seems to assume that server does no buffering on the written data. Is server allowed to buffer? I think it should be, for performance reasons. If it is, should their be some possibility for application to force/finish the output (such as special value to writer, or another keyword argument)?

The concern is reasonable as a server implementer. Clack does not specifically enforce synchronous communication in that case, so it is up to the web server implementation.

  • Is there some standard setup where I get the FD parameter to the RUN function?

Clack allows web servers to take optional keyword parameters in run. Woo takes :fd keyword to specify it.

fukamachi commented 2 years ago

Incidentally, I looked at the writer-stream from lack utils and it seems to implement finishing by closing the output; this looks to me as a different action (I may want to finish output many times, but close only once, and finishing should wait for confirmation)

Good point. I never thought of the case. It might be nice to have another function to differentiate those operations.

zellerin commented 2 years ago

Thanks for answers,

Clack allows web servers to take optional keyword parameters in run. [Woo](https://github.com/fukamachi/woo) takes :fd keyword to specify it.

Probably I was not clear. I was interested if there is some standard component that does the "pass the fd in" part that I could plug into (or if it is just integrated part of woo).

fukamachi commented 2 years ago

Probably I was not clear. I was interested if there is some standard component that does the "pass the fd in" part that I could plug into (or if it is just integrated part of woo).

In that sense, Clack does not have a unified interface for passing fd. :fd keyword is just an extension of Woo.

The reason is that most servers don't accept fd. There seems to be no reason for a new server to use a keyword other than :fd for receiving fd, though.

zellerin commented 2 years ago

Ok, thanks for info. It was still worth asking I think.