commit 2bc7d6e63a28f1f89ea3c8356d17f4735e88905b
parent 14e15d430a5b3de9f82b9346213c0703d2d63276
Author: Johann150 <johann.galle@protonmail.com>
Date: Sun, 6 Jun 2021 12:52:47 +0200
better error messages when directory listing is disabled
This is possibly also related to #60.
Instead of showing a generic not found error, this shows both the admin and
the user that the directory exists, but directory listing is disabled.
Diffstat:
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
+Thank you to Oliver Simmons (@GoodClover) for contributing to this release.
+
+### Added
+* tests for symlink files (#60)
+ Symlinks were already working before.
+
+### Changed
+* Visiting a directory without `index.gmi` and `.directory-listing-ok` now returns a different error message to better show the cause of the error.
+ To retain the current behaviour of showing a `51 Not found, sorry.` error, add the following line to the respective directories' `.meta` file:
+```
+index.gmi: 51 Not found, sorry.
+```
## [3.0.3] - 2021-05-24
Thank you to @06kellyjac, @cpnfeeny, @lifelike, @skittlesvampir and @steko for contributing to this release.
diff --git a/src/main.rs b/src/main.rs
@@ -303,11 +303,13 @@ impl RequestHandle {
let peer_addr = if ARGS.log_ips {
stream
.peer_addr()
- .or(Err(format!(
- // use nonexistent status code 01 if peer IP is unknown
- "{} - \"\" 01 \"IP error\" error:could not get peer address",
- local_addr,
- )))?
+ .map_err(|_| {
+ format!(
+ // use nonexistent status code 01 if peer IP is unknown
+ "{} - \"\" 01 \"IP error\" error:could not get peer address",
+ local_addr,
+ )
+ })?
.ip()
.to_string()
} else {
@@ -456,9 +458,14 @@ impl RequestHandle {
// if the path ends with a slash or the path is empty, the links will work the same
// without a redirect
path.push("index.gmi");
- if !path.exists() && path.with_file_name(".directory-listing-ok").exists() {
- path.pop();
- return self.list_directory(&path).await;
+ if !path.exists() {
+ if path.with_file_name(".directory-listing-ok").exists() {
+ path.pop();
+ return self.list_directory(&path).await;
+ } else {
+ self.send_header(51, "Directory index disabled.").await?;
+ return Ok(());
+ }
}
} else {
// if client is not redirected, links may not work as expected without trailing slash