Commit Graph

120 Commits

Author SHA1 Message Date
Paco Pascal 7145426710 --forward-https has priority over --auth. Therefore, if the server's
running with both options and the client connects via HTTP, a redirect
will occur instead of the authentication being granted or denied.

The code for handling a HTTPS redirect has been moved out of
process_get() and put into redirect_https() and is_https_redirect().
The latter checks if redirect_https() should be called.
2021-08-22 13:01:28 +10:00
Paco Pascal 49baf385e1 Forward to HTTPS if X-Forwarded-Proto is equal to "http". This can be
enabled with "--forward-https".

This might be useful if darkhttpd is behind a reverse proxy that
supports SSL.
2021-08-22 13:01:28 +10:00
Tom Dryer 59b30c5cbc
Fix high CPU usage when timeout is disabled (#8)
When darkhttpd is running with `--timeout 0` (timeout disabled), and any
connection is idle, it will use 100% of the CPU. This happens because
`select` returns immediately when its timeout is zero, causing the main
`httpd_poll` loop to spin.

Fix this by adding a check to `httpd_poll` making `select` always
receive a `NULL` timeout when `timeout_secs` is zero.
2021-06-27 11:41:19 +10:00
Tom Dryer 667edacaa3
Fix hung connection from consecutive requests (#7)
A client making quick consecutive requests with keep-alive, such as `ab`
with `-k`, can cause the connection to become hung.

This happens because of an optimization in `http_poll` function. When a
connection state becomes `DONE`, `httpd_poll` recycles the connection
and immediately calls `poll_recv_request`. However, it doesn't handle
this resulting in the connection state becoming `DONE` again. If this
occurs, the state stays in `DONE`, and the further calls to `httpd_poll`
ignore the connection.

Fix this by calling `poll_recv_request` in a loop until the state is no
longer `DONE`.

* Enable TCP_NODELAY optimization

It looks like `TCP_NODELAY` was disabled due to the bug fixed in the
previous commit. Enabling it substantially improves keep-alive
performance with `ab`:

Before:

```
Time per request:       0.272 [ms] (mean)
```

After:

```
Time per request:       0.033 [ms] (mean)
```

* Remove keep-alive optimization from `httpd_poll`

Benchmarking with `ab` shows that bypassing `select` for keep-alive
connections in the `DONE` state doesn't significantly impact
performance. Since this optimization previously caused a bug, remove it.
2021-06-14 11:44:55 +10:00
Emil Mikulic 81b491e60a Declare vars outside of for() loop for -std=c90.
Fixes #2.
2021-03-21 15:03:14 +11:00
Emil Mikulic dc0fd7ecdc Don't include URL or method in default_reply. 2021-02-21 17:09:27 +11:00
Emil Mikulic 3058f910d9 File listings: decoded URL in title and heading.
Also HTML-escape title, heading, and file names.
2021-02-21 16:47:14 +11:00
ilmich 2b37151afc Add support for logging with syslog.
The motivation is that with busybox, the implementation of syslog has a
builtin log rotation.

So I don't need an external logrotate for darkhttpd.
2021-02-10 18:51:24 +11:00
Emil Mikulic f72e8d6afe Bump version past release. 2021-02-10 18:48:57 +11:00
Emil Mikulic afeb47443a [ darkhttpd 1.13 release ]
And bump copyright year.
2021-01-18 00:50:36 +11:00
Emil Mikulic 8cca3b6c87 Fix a bug when a range is requested and the request is too large. 2021-01-17 23:00:32 +11:00
Emil Mikulic c1cd3d0e2d Fix bug in handling of bad requests. 2021-01-17 22:11:54 +11:00
decho 1990aee864 directory listing: Send viewport meta tag 2021-01-05 19:31:16 +11:00
Emil Mikulic 6a82e67772 Avoid file size overflow on 32-bit systems.
Reported by: Mariusz Stokłosa <krokator@gmail.com>
2020-07-01 22:07:12 +10:00
solsTiCe d'Hiver d777aacd98 Log using Combined Log Format (commonly found in apache log)
Commonly found in Apache log. It adds 2 fields upon the Common Log
Format (referer and user-agent).

https://en.wikipedia.org/wiki/Common_Log_Format

It is just a matter of reordering what your were already logging with a
new date formatting.

* We are cheating because we always assume HTTP/1.1 as the request
  header.

* We assume the user name is unknown.
2020-07-01 21:47:26 +10:00
Andreas Gal 85609c8095 add mp4 mine type 2020-07-01 21:36:04 +10:00
Teo Klestrup Röijezon 07af05745e Add SVG mime type. 2020-07-01 21:29:25 +10:00
Emil Mikulic e9c474dfac Don't send extra blank line when --auth is disabled. 2020-07-01 21:22:17 +10:00
Ryan Jacobs 027b0c90e5 Add basic-auth support. 2020-07-01 20:48:02 +10:00
Emil Mikulic f41be73a66 Silence -Wparentheses warning. 2020-07-01 20:15:36 +10:00
Mathieu Gagnon e09f869072 Fix handling of files with question mark in the name. 2020-07-01 20:15:03 +10:00
Emil Mikulic 36aadb6f90 Tweak macros to avoid extraneous semicolons.
-Wextra-semi-stmt complains about this.
2020-07-01 19:43:30 +10:00
Emil Mikulic 27e489aab7 Memory sanitizer workaround: unpoison fd_sets.
This is necessary with clang-9, maybe earlier.
2020-07-01 19:18:13 +10:00
Luca Weiss e2e693e1cf Add application/wasm mimetype
Useful for serving wasm files.

See https://github.com/ruffle-rs/ruffle/wiki/Using-Ruffle#configure-wasm-mime-type
2020-07-01 19:01:32 +10:00
Emil Mikulic f0a8dc6c6c Add --timeout cmdline option. 2018-12-10 23:35:31 +11:00
Emil Mikulic 38362a4111 Bump copyright year. 2018-12-10 23:34:34 +11:00
Emil Mikulic 744bac5cb8 In debug mode: time how long select() takes. 2018-12-10 21:03:17 +11:00
Emil Mikulic 89af6956e2 Fix timeouts to close connections. 2018-12-10 21:03:17 +11:00
Emil Mikulic c2fbca8d5a If accept() fails, don't exit.
Temporarily stop accept()ing if we ran out of fds.

Suggested by: Bert Gijsbers
2018-12-10 00:29:51 +11:00
Emil Mikulic bdae96c653 Switch make_safe_url() to more efficient implementation.
Contributed by: Bert Gijsbers
2018-12-09 23:44:36 +11:00
Emil Mikulic aad4574163 Bounds check first.
Found with: cppcheck
2018-12-09 22:40:29 +11:00
Emil Mikulic 41b68476c3 [ darkhttpd 1.12 release ] 2016-01-28 01:16:20 +11:00
Emil Mikulic 15eda67214 Fix IPv6 memory corruption crash on FreeBSD.
getsockname() into addrin6 instead of addrin when ipv6 is requested.
2016-01-28 01:06:08 +11:00
Emil Mikulic 27c899c165 Obvious %lld -> %llu correction.
Caught with cppcheck.
I have no idea why it wasn't caught earlier.
2016-01-23 20:13:17 +11:00
Emil Mikulic 26129431b9 Be explicit if the binary was built without IPV6 support.
Fix the number of newlines involved.
2016-01-23 19:57:23 +11:00
Emil Mikulic 2ced9cac51 Try to build with IPv6 by default. 2016-01-23 19:55:33 +11:00
Emil Mikulic 79475170b2 Bump copyright year. 2016-01-23 19:54:07 +11:00
Emil Mikulic ea93b88e62 Move HAVE_INET6 guards to avoid the appearance of functions that don't return.
Fixes GCC warnings.
2016-01-13 20:24:36 +11:00
Emil Mikulic 24fa3798b2 Explicitly cast getpid() result to int.
This placates cppcheck.
2016-01-13 20:18:30 +11:00
Emil Mikulic 955762645d Tidy up UTF-8 after merge. 2016-01-13 20:04:29 +11:00
Emil Mikulic 4d34abd3c9 Merge branches with UTF-8 changes. 2016-01-13 20:00:44 +11:00
Alexey 9205377852 I added utf-8 in your code: "Content-Type: text/html; charset=utf-8\r\n"
(in few places)
2016-01-13 19:59:40 +11:00
Stephen Zhang 26785ceafe Add '<meta charset="utf-8"/>' to the html header
I think most non-English user would need it to fix error encoding in displaying
file name in the web page.
2016-01-13 19:56:23 +11:00
Hugh Wang 4edc50c42f Use UTF-8 as the encoding for directory listing. 2016-01-13 19:53:14 +11:00
Hugh Wang 72159c5010 Add support for IPv6. 2015-12-20 21:59:20 +08:00
Emil Mikulic 02b02a7615 Check the bound first.
Found with cppcheck.
2015-05-20 00:06:59 +10:00
Emil Mikulic 1c5fdb5607 Escape URLs according to RFC3986.
Previously, we weren't escaping parentheses when generating directory listings.

Pointed out by: Wijatmoko U. Prayitno
2015-05-19 22:04:39 +10:00
Emil Mikulic c4c0034242 Add --default-mimetype flag. 2015-05-19 21:40:26 +10:00
Emil Mikulic e9aeaba7fe Add test for --no-listing. 2015-05-19 21:30:59 +10:00
Emil Mikulic fc8e127bb7 Fix memory leak. 2015-05-19 21:17:42 +10:00