aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-04-05 06:50:30 +0000
committerFuwn <[email protected]>2022-04-05 06:50:30 +0000
commit942f4c5cd8c117c5f0102176a411fb6514e1b0cc (patch)
treefaf9f3dc6589b1087369f0ac7937be23a5edf8d9
parentrefactor: pass lambda to signal (diff)
downloadmaple-942f4c5cd8c117c5f0102176a411fb6514e1b0cc.tar.xz
maple-942f4c5cd8c117c5f0102176a411fb6514e1b0cc.zip
feat: can respond to unique indexes
-rw-r--r--maple/maple.cc27
1 files changed, 22 insertions, 5 deletions
diff --git a/maple/maple.cc b/maple/maple.cc
index 94b1005..2fce54d 100644
--- a/maple/maple.cc
+++ b/maple/maple.cc
@@ -171,10 +171,18 @@ auto main() -> int {
path = path.substr(0, path.size() - 2); // Remove "\r\n"
path.erase(0, 9); // Remove "gemini://"
- path = path.substr(
- path.find_first_of('/'),
- path.size() - 1
- ); // Remove host
+
+ // Try to remove the host, if you cannot; it must be a trailing slash-less
+ // hostname, so we will respond with the index.
+ size_t found_first = path.find_first_of('/');
+ if (found_first != std::string::npos) {
+ path = path.substr(
+ found_first,
+ path.size() - 1
+ ); // Remove host
+ } else {
+ path = "/index.gmi";
+ }
// Remove junk, if any
index_of_junk = path.find_first_of('\n');
@@ -200,7 +208,16 @@ auto main() -> int {
response << "20 text/gemini\r\n" << buffer.str();
} else {
- response << "51 The server (Maple) could not find the specified file.\r\n";
+ if (path.empty() || path == "/") {
+ std::ifstream file(".maple/gmi/index.gmi");
+ std::stringstream buffer;
+
+ buffer << file.rdbuf();
+
+ response << "20 text/gemini\r\n" << buffer.str();
+ } else {
+ response << "51 The server (Maple) could not find the specified file.\r\n";
+ }
}
std::cout << "requested " << path << std::endl;