Commit graph

33 commits

Author SHA1 Message Date
5b6f8e5083 Read from template files with placeholder replacement
Some checks failed
continuous-integration/drone/push Build is failing
2020-08-28 00:46:08 +02:00
329dedc33b Read dirlist from templates
Some checks failed
continuous-integration/drone/push Build is failing
Reads header, footer and entry templates from files defined in config.h.
Defaults to original output if not found.
2020-08-25 21:08:23 +02:00
Laslo Hunhold
bbd47e1427
Specify UTF-8 for non-binary content-types
If charset is unspecified, the encoding falls back to ISO 8859-1 or
something else that is defined in HTTP/1.1.

Given there is no reason not to use UTF-8 nowadays[0] and one can convert
legacy encodings to UTF-8 easily, if the case comes up, it is a sane
default to specify it in the config.def.h.

[0]: https://utf8everywhere.org/

Signed-off-by: Laslo Hunhold <dev@frign.de>
2019-01-02 17:04:23 +01:00
Laslo Hunhold
6b55e36036 Introduce flag-centric usage
The config.h-interface has proven to be very effective for a lot of
suckless tools, but it just does not make too much sense for a web
server like quark.

 $ quark

If you run multiple instances of it, you want to see in the command line
(or top) what it does, and given the amount of options it's logical to
just express them as options given in the command line.
It also is a problem if you can modify quark via the config.h,
contradicting the manual. Just saying "Well, then don't touch config.h"
is also not good, as the vhost and map options were only exposed via
this interface.

What is left in config.h are mime-types and two constants relating to
the incoming HTTP-header-limits.

In order to introduce these changes, some structs and safe utility
functions were added and imported from OpenBSD respectively.
2018-03-05 00:14:25 +01:00
Laslo Hunhold
b40b11a40e Fix the regex in the example
Thanks Hiltjo!
2018-02-27 13:00:23 +01:00
Laslo Hunhold
7b7f166dd5 Add target prefix mapping
This allows e.g. to redirect when a directory has been moved.
2018-02-27 12:43:05 +01:00
Laslo Hunhold
02d6ae5a57 Add support for adding a prefix to a target when matching vhosts
This makes quark's vhost-handling very powerful while still being
simple.

Imagine you have a website with a subdomain you really want
to move back to your main domain.
Say the subdomain is called "old.example.org" and you want to serve it
under "example.org" but in the subdirectory "old/", i.e. you want to
redirect a request "old.example.org/subdir/" to "example.org/old/subdir".

For a vhost-handler that only takes 4 arguments for each vhost this is
actually pretty powerful.
2018-02-27 11:36:24 +01:00
Hiltjo Posthuma
2a5ab48294 use extended regex and fix example regex for realsies 2017-07-22 13:23:10 +02:00
Laslo Hunhold
8ec042a1ba Properly escape backslash in regex 2017-07-21 18:37:55 +02:00
Laslo Hunhold
10d2ffe53a Fix example regex in vhosts
Thanks Hiltjo for noticing this!
2017-07-21 18:36:02 +02:00
Laslo Hunhold
d7cf0d7f57 Reorder config.def.h a bit 2017-07-11 13:52:41 +02:00
Quentin Rameau
e592bbc0fe Integrate compiled regex into vhost array 2017-07-11 13:45:57 +02:00
Laslo Hunhold
000553d8c5 Add vhost support
As given in the config, we match a regex of hosts to a canonical host
which points to an internal directory.
Regexes are compiled on initialization, so we can error out early.
The rest is just modifications to use relative directories rather than
absolute ones, as we chdir() into the vhost directories dynamically.

Given we normalize the targets beforehand, there is no danger of
malformed requests escaping the vhost-context.
2017-07-11 12:55:39 +02:00
Hiltjo Posthuma
c369738fa4 make directory listing a run-time flag
remove const in the config.h since it can be changed at run-time now.
2017-06-27 23:31:08 +02:00
Hiltjo Posthuma
434f2b3067 config.def.h: add jpeg alias, ogg audio mimetype 2017-06-27 23:31:08 +02:00
Laslo Hunhold
6347e2ec3e Rewrite quark from the ground up again
I noticed that the data structures didn't allow a flexible handling of
the code while trying to extend it to support if-modified-since-responses.
To tackle this, I refactored the data structures and proceeded to
rewrite the server from the ground up, implementing all present features
plus fixing a lot of bugs and introducing the 304 header handling as
requested by many people.

Please report bugs if you find them.

While at it, I refactored the build system as well and updated all
surrounding files respectively.
2017-06-20 21:40:00 +02:00
FRIGN
f04929e729 Add a few more mime types 2016-09-02 11:09:49 +02:00
FRIGN
0ce86bba15 Initial commit of quark rewrite
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.
2016-09-02 09:59:02 +02:00
FRIGN
0e8cac1ee4 Prepare repository for rewrite
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.
2016-09-02 09:46:01 +02:00
FRIGN
4c14a02754 Fix syntax error in config.def.h
Thanks to Boris Egorov for finding this!
2015-05-24 16:49:42 +02:00
Hiltjo Posthuma
70359ae2e9 config: add some more common mime-types 2014-11-30 23:35:48 +01:00
Ivan Delalande
e42bb27846 change the behavior of docroot
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.
2014-11-30 23:35:10 +01:00
FRIGN
5dac8de322 Allow dir-listing to be a configurable option 2014-08-20 20:47:29 +02:00
Hiltjo Posthuma
8aa3e3f48f config: allow to set options as application arguments 2014-08-14 17:43:46 +02:00
FRIGN
34b584e2cb Fix mime-handling with default mime
Now it should work. It doesn't make much sense to tweak the default
mime-type, given octet-stream is the default and there are
no real alternatives which would make sense.

Thanks Hiltjo and sin!
2014-08-09 22:29:08 +02:00
FRIGN
93f27cd081 Change default mimetype to application/octet-stream
and move it to config.def.h instead of hiding it in the code.
2014-08-09 21:14:40 +02:00
garbeam@gmail.com
3a9701d828 applied rransom's quark patch for FreeBSD compliance, thanks 2011-06-26 10:51:42 +01:00
Anselm R Garbe
d6cbb5b9d9 preparing Request abstraction, ongoing 2011-02-16 20:29:55 +00:00
Anselm R Garbe
a61a51b91d applied Szabolcs patch, added him to LICENSE 2011-02-13 12:46:34 +00:00
Anselm R Garbe
5e9814c847 made simple CGI working, quark can be used to run werc 2010-03-28 11:31:30 +00:00
Anselm R Garbe
3e45a7c0ba added command line interface 2010-03-28 02:14:01 +00:00
Anselm R Garbe
a20243ea7c added basic HEAD support, some bug fixes 2010-03-28 01:57:44 +00:00
Anselm R Garbe
07db66c273 implemented very basic cgi support 2010-03-28 01:09:14 +00:00
Renamed from config.h (Browse further)