diff --git a/src/application.cpp b/src/application.cpp index 41a8122..57364d2 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -122,6 +122,7 @@ GitApp::GitApp(cppcms::service &srv, const RepoScanner *scanner) allow_clone_ = resolve_allow_clone(settings().get("git.allow_clone", false)); // Root arrives as "" because script_name "/" is stripped; accept both. + dispatcher().assign(R"(^/robots\.txt$)", &GitApp::robots_txt, this); dispatcher().assign("^/?$", &GitApp::frontpage, this); dispatcher().assign("^/about/?$", &GitApp::about, this); dispatcher().assign("^/static/(.+)$", &GitApp::static_file, this, 1); @@ -131,10 +132,10 @@ GitApp::GitApp(cppcms::service &srv, const RepoScanner *scanner) dispatcher().assign("^/repos/([^/]+)/blame/(.+)$", &GitApp::blame, this, 1, 2); dispatcher().assign("^/repos/([^/]+)/object/([0-9a-f]+)$", &GitApp::object, this, 1, 2); dispatcher().assign("^/repos/([^/]+)/log/?$", &GitApp::log, this, 1); - dispatcher().assign("^/repos/([^/]+)/commit/([0-9a-f]+)\\.patch$", &GitApp::commit_patch, this, 1, 2); + dispatcher().assign(R"(^/repos/([^/]+)/commit/([0-9a-f]+)\.patch$)", &GitApp::commit_patch, this, 1, 2); dispatcher().assign("^/repos/([^/]+)/commit/([0-9a-f]+)$", &GitApp::commit, this, 1, 2); dispatcher().assign("^/repos/([^/]+)/tags/?$", &GitApp::tags, this, 1); - dispatcher().assign("^/repos/([^/]+)/tags/(.+)\\.tar\\.gz$", &GitApp::tag_archive, this, 1, 2); + dispatcher().assign(R"(^/repos/([^/]+)/tags/(.+)\.tar\.gz$)", &GitApp::tag_archive, this, 1, 2); dispatcher().assign("^/repos/([^/]+)/tags/(.+)$", &GitApp::tag, this, 1, 2); dispatcher().assign("^/repos/([^/]+)/branches/?$", &GitApp::branches, this, 1); // Only wire up the clone endpoints when enabled, so a disabled server never @@ -160,6 +161,13 @@ void GitApp::main(std::string url) { cppcms::application::main(url); } +void GitApp::robots_txt() { + response().content_type("text/plain; charset=utf-8"); + response().out() << "User-agent: *\n" + "Disallow: /repos/*/blame/\n" + "Allow: /\n"; +} + void GitApp::static_file(std::string rel) { if (rel.find("..") != std::string::npos) { show_error(403, "Forbidden"); diff --git a/src/application.h b/src/application.h index a606504..338cfc3 100644 --- a/src/application.h +++ b/src/application.h @@ -60,6 +60,7 @@ private: void branches(std::string name); void commit(std::string name, std::string oid); void commit_patch(std::string name, std::string oid); + void robots_txt(); void static_file(std::string rel); // Serves Git's Smart HTTP protocol (clone/fetch) by proxying to