Commit Graph

30 Commits

Author SHA1 Message Date
Max Wipfli
79a47d9bd3 WebServer: Add support for HTTP basic authentication
This enables the WebServer to run protected by a username and password.
While it isn't possible to access such a protected server from inside
Serenity as of now (because neither the Browser nor pro(1) support
this), this may very well be the case in the future. :^)
2021-06-11 11:37:15 +02:00
Max Wipfli
e77ca79897 WebServer: Move server configuration into WebServer::Configuration
This moves the configuration of the web server, which currently only
consists of the root path, into a new class, Configuration. Since the
configuration is global and not per client, it is accessed by a
singleton getter.

This change simplifies future extensions of the configurable parameters.
2021-06-11 11:37:15 +02:00
Max Wipfli
2d18d3f329 WebServer: Use canonical reasons phrases for error responses
This changes the Client::set_error_response() to not take a "message"
anymore. It now uses the canonical reason phrase which is derived from
the response code.
2021-06-11 11:37:15 +02:00
Max Wipfli
977b3509f2 WebServer: Sort entries in directory listing 2021-06-11 11:37:15 +02:00
Max Wipfli
2c5a8462ec WebServer: Append trailing slash for directory links
This adds trailing slashes to all links to directories (when listing the
directory contents). This avoids the redirect that would otherwise
happen when browsing to those directories.
2021-06-11 11:37:15 +02:00
Max Wipfli
e4f3a5fe37 WebServer: Make ".." equal to "." in server root directory
In the web server root directory, ".." has to be handled specially,
since everything above it does not exist from the point of view of the
user. The most sensible thing to do is to make ".." equal to ".". This
is also what ls(1) does for "/" and what "http://localhost/../"
evaluates to.

This also fixes a bug where stat() would fail on the directory above the
root directory, since it hasn't been unveiled for the process.
2021-06-11 11:37:15 +02:00
Max Wipfli
450a24c8c9 WebServer: Refuse to respond to requests for device files
Responding with some device files such as /dev/random never terminates,
so let's just refuse that.
2021-06-11 11:37:15 +02:00
Max Wipfli
eb6adbabef WebServer: Use outln() instead of printf() 2021-06-11 11:37:15 +02:00
Max Wipfli
6e6ff844d3 WebServer: Defer invocation of Client::remove_from_parent()
This is necessary to avoid trying to destruct the on_ready_to_read
function from inside the function. This fixes #7810.
2021-06-11 11:37:15 +02:00
Max Wipfli
5408111aff WebServer: Use east const style in Client.{cpp,h}
This also removes two unused headers.
2021-06-11 11:37:15 +02:00
Max Wipfli
a603e69599 AK+Everywhere: Replace usages of URLParser::urlencode() and urldecode()
This replaces all occurrences of those functions with the newly
implemented functions URL::percent_encode() and URL::percent_decode().
The old functions will be removed in a further commit.
2021-06-01 09:28:05 +02:00
Edwin Hoksberg
e68780e1ad WebServer: Put dbgln's behind WEBSERVER_DEBUG
These dbgln's caused excessive load in the WebServer process,
accounting for ~67% of the processing time when serving a webpage
with a bunch of resources like serenityos.org/happy/2nd/.
2021-05-30 17:41:56 +01:00
Linus Groh
75ea1bd346 WebServer: Exit when the given port is invalid
Similar to an invalid listen address, we should not fallback to the
default port (8000) but instead exit with an error.
2021-05-30 14:11:53 +01:00
Linus Groh
7fa3033ca8 WebServer: Replace printf()/fprintf(stderr) with outln()/warnln() 2021-05-30 14:07:58 +01:00
Edwin Hoksberg
2deffeb74d WebServer: Add optional listen address argument
With this we can make the Webserver listen on
another address than the default of "0.0.0.0".
2021-05-30 13:03:59 +01:00
DexesTTP
9f42ccd639 WebServer: Fix jailbreaking of server via .. relative paths
The recent patch to LexicalPath allowed relative paths like ../ to work
in requests to WebServer. This wasn't too dangerous because of unveil,
but let's still fix this :^)
2021-05-18 09:32:10 +02:00
Gunnar Beutner
8c96640157 WebServer: Set no-cache header for responses
This sets the Pragma: no-cache header. Using Cache-Control would be
preferable but that's not part of the HTTP/1.0 standard.
2021-05-17 21:28:34 +02:00
Gunnar Beutner
7aca2d181a WebServer: Don't read until EOF
There's no guarantee that the client has closed the socket for
writing. Instead we should just read until the first empty line.

Fixes #7064.
2021-05-17 21:28:34 +02:00
Gunnar Beutner
53d0150827 AK+Userland: Remove nullability feature for the ByteBuffer type
Nobody seems to use this particular feature, in fact there were some
bugs which were uncovered by removing operator bool.
2021-05-16 17:49:42 +02:00
Andreas Kling
31d4bcf5bf Userland: Tighten a *lot* of pledges! :^)
Since applications using Core::EventLoop no longer need to create a
socket in /tmp/rpc/, and also don't need to listen for incoming
connections on this socket, we can remove a whole bunch of pledges!
2021-05-13 23:28:40 +02:00
Ali Mohammad Pur
a91a49337c LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
2021-05-12 11:00:45 +01:00
Andreas Kling
f0687dbbb7 Services: Convert StringBuilder::appendf() => AK::Format 2021-05-07 21:12:09 +02:00
Gunnar Beutner
b613817bca Userland: Fix 64-bit portability issues 2021-05-03 08:42:39 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Jean-Baptiste Boric
ade6343fca Userland: Fix printf specifiers with off_t
In theory we should probably use the 'j' qualifier, but we don't
support it.
2021-03-17 23:22:42 +01:00
Brendan Coles
4ae3bfa40d WebServer: Serve X-Frame-Options and X-Content-Type-Options HTTP headers 2021-03-06 15:04:16 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
AnotherTest
bdda1600d0 WebServer: Stream the downloaded files
...instead of reading them into memory first.
This makes it possible to download large files from WebServer.
2021-01-30 14:12:14 +01:00
asynts
24888457d5 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-22 22:14:30 +01:00
Andreas Kling
c7ac7e6eaf Services: Move to Userland/Services/ 2021-01-12 12:23:01 +01:00