Roughly 700 LOC (half of the old quark on the Hiltjo branch) in size,
this rewrite supports partial content and other good stuff that will
make it fun again to use quark for simple static purposes.
The error checking is rigorous and strict and it will report proper
error codes back to the client whenever there was a problem or the
request was invalid in some way.
A cool feature is the support for listening on a UNIX-domain socket,
which will in the long run allow us to solve problems with virtual hosts
and other things in separate programs. But until then, this should be
robust enough for most use-cases.
This resets quark's version to 0, but this was no problem as there
haven't been any quark releases yet.
Feedback is appreciated.
It was sad to see that quark never got the attention it deserved in my
opinion. However, there were good reasons why that was the case.
The project lost focus by trying to add CGI support, which in all
fairness worked only half of the time.
For the rest of the use cases, a static server to make it dead simple to
publish a directory, it was also pretty bad, given it does not support
partial content. Seeking in a mp3 was impossible and it was very
frustrating.
Long ago we discussed in the team how exciting it would be to test out
new concepts of having a web server that listens on a UNIX-domain
socket, potentially allowing new concepts for realizing virtual hosts
and other things.
It took me half a year to make the decision to rewrite quark, so it is
now time to purge the repo and push the initial commit.
Change the behavior of docroot, which is now used as a prefix path for
all file operations related to static files. And add chrootdir, which is
just the old docroot behavior and allows to control the path into which
quark will chroot.
Not having properly distinct configuration variables for chroot,
document root and CGI root was specially annoying since commit 2822488
which allowed users to retrieve the CGI script or binary by just
guessing its path, since quark was chrooting into docroot before
anything else, and thus the CGI script/binary was in the user accessible
path.
This is implemented by moving the reqbuf buffer in the middle of a
bigger buffer, reqpath. That buffer contains the value of docroot at its
beginning and reqbuf simply points to the first byte after this value.
This reverts commit 68f51ac37a.
The idea is good, but we just didn't yet get the right format
for the reading-cycle, which effectively keeps offset at 0
when it's all done in one read.
Let's call it a day and get back to the drawing-boards
tomorrow.
CGI applications can specify a HTTP status to output with the Status:
header. For simplicity the CGI application must use this header on the
first line. With this change cloning git repositories over HTTP with
cgit works.
in config.mk specify _GNU_SOURCE and _POSIX_C_SOURCE instead of
_GNU_SOURCE, this is for getline().
- set some more environment variables (PATH_INFO for example is used by
cgit). Also set REMOTE_ADDR, SERVER_PORT, SERVER_SOFTWARE.
- when a file is requested in cgi mode serve it, if it doesn't exist,
pass it to the CGI script (needed for cgit image/CSS).
If the client decides not to listen, it's not that much of a problem.
Don't flood the logs with "Broken pipe"-messages by silently letting
this "error" pass.
Streaming a file (through mplayer for instance), the socket would
block, because mplayer fills its buffer sequentially.
We would've never gotten to a write(.., n) == n.
Instead, do it like we read from files and accept the fact clients
can accept data chunk-wise, too.
The reason why this error went unnoticed is that I added a faulty
printf-directive (%ls for ssize_t), which silently produced
no output.
Thanks to sin for fixing the %ls -> %zd error, as it made me look
at the code again.
When the client requests a hidden file, we forbid access.
401 is mostly used when a login is required and hasn't been provided.
Thus, given we don't offer a login-prompt to access hidden and bogus
files but categorically reject them, 403 makes more sense here.