Skip to content

Commit

Permalink
Serve directories (completely rewritten)
Browse files Browse the repository at this point in the history
  • Loading branch information
esote committed Jan 30, 2020
1 parent d2780d9 commit 87e18f6
Show file tree
Hide file tree
Showing 7 changed files with 573 additions and 203 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROG= filesrv
SRCS= filesrv.c
SRCS= filesrv.c respond.c

CFLAGS= -O2 -fstack-protector -D_FORTIFY_SOURCE=2 -pie -fPIE
LDFLAGS= -Wl,-z,now -Wl,-z,relro
Expand Down
36 changes: 12 additions & 24 deletions README
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
NAME
filesrv - single-file web server
filesrv - filesystem web server

SYNOPSIS
filesrv [-l] [-p port] [-t timeout] file
filesrv [-d] [-p port] [-t timeout] [-u user] dir

DESCRIPTION
filesrv is a single-file web server. It handles TCP connections serially
to avoid fork exhaustion during high traffic. The -p option specifies
the listening port. The default is to listen on port 8080.
filesrv is a filesystem web server. It responds with directory listings
or file contents based on the request path. The -d option daemonizes the
process. The -p option specifies the listening port, otherwise 8080 by
default. -t option specifies the read and write timeout, otherwise 10
seconds by default.

The -l option specifies that the input file requires lazy reading. This
is usually the case with large files which cannot be comfortably
pre-loaded. The default behavior is to memory-map the entire input file.

The -t option specifies the write timeout in seconds. A timeout of 0
waits indefinitely. The default timeout is 1 second.

filesrv will try to persist connection errors, and will continue to
accept connections after it encounters any errors. It does not read any
portion of the request data.

When sent SIGINT, filesrv will clean itself up and exit gracefully.

If given port 0, filesrv will print the port number assigned by the
kernel.

If filesrv is run with root privileges, it will chroot to the current
working directory after opening the input file.
The -u option causes filesrv to drop privileges to the specified user.
This is only available when filesrv is run as root. It is useful when
listening on a privileged lower port without needing persistent root
access.

AUTHORS
filesrv was written by Esote.

COPYRIGHT
Copyright (c) 2019 Esote. There is NO warranty. You may redistribute
Copyright (c) 2020 Esote. There is NO warranty. You may redistribute
this software under the terms of the GNU Affero General Public License.
For more information, see the LICENSE file.
8 changes: 8 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TODO:
handle HEAD requests

respond with last-modified header

handle content range requests

infer file MIME type using https://mimesniff.spec.whatwg.org/
61 changes: 22 additions & 39 deletions filesrv.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\"
.\" Copyright (C) 2019 Esote
.\" Copyright (C) 2020 Esote
.\"
.\" This program is free software: you can redistribute it and/or modify
.\" it under the terms of the GNU Affero General Public License as published
Expand All @@ -14,67 +14,50 @@
.\" You should have received a copy of the GNU Affero General Public License
.\" along with this program. If not, see <https://www.gnu.org/licenses/>.
.\"
.Dd $Mdocdate: December 9 2019 $
.Dd $Mdocdate: January 30 2019 $
.Dt FILESRV 1
.Os
.Sh NAME
.Nm filesrv
.Nd single-file web server
.Nd filesystem web server
.Sh SYNOPSIS
.Nm filesrv
.Op Fl l
.Op Fl d
.Op Fl p Ar port
.Op Fl t Ar timeout
file
.Op Fl u Ar user
dir
.Sh DESCRIPTION
.Nm filesrv
is a single-file web server.
It handles TCP connections serially to avoid fork exhaustion during high
traffic.
is a filesystem web server.
It responds with directory listings or file contents based on the request path.
The
.Fl p
option specifies the listening port.
The default is to listen on port 8080.
.Pp
The
.Fl l
option specifies that the input file requires lazy reading.
This is usually the case with large files which cannot be comfortably
pre-loaded.
The default behavior is to memory-map the entire input file.
.Pp
.Fl d
option daemonizes the process.
The
.Fl p
option specifies the listening port, otherwise 8080 by default.
.Fl t
option specifies the write timeout in seconds.
A timeout of 0 waits indefinitely.
The default timeout is 1 second.
option specifies the read and write timeout, otherwise 10 seconds by default.
.Pp
The
.Fl u
option causes
.Nm filesrv
will try to persist connection errors, and will continue to accept connections
after it encounters any errors.
It does not read any portion of the request data.
.Pp
When sent
.Dv SIGINT ,
.Nm filesrv
will clean itself up and exit gracefully.
.Pp
If given port 0,
.Nm filesrv
will print the port number assigned by the kernel.
.Pp
If
to drop privileges to the specified user.
This is only available when
.Nm filesrv
is run with root privileges, it will chroot to the current working directory
after opening the input file.
is run as root.
It is useful when listening on a privileged lower port without needing
persistent root access.
.Sh AUTHORS
.Nm filesrv
was written by
.An Esote .
.Sh COPYRIGHT
Copyright
.Pq c
2019 Esote.
2020 Esote.
There is NO warranty.
You may redistribute this software under the terms of the GNU Affero General
Public License.
Expand Down
Loading

0 comments on commit 87e18f6

Please sign in to comment.