[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-1' - Makefile.am robots.txt wsd/LOOLWSD.cpp

Andras Timar andras.timar at collabora.com
Tue Feb 20 14:33:34 UTC 2018


 Makefile.am     |    4 +---
 robots.txt      |    2 --
 wsd/LOOLWSD.cpp |   29 +++++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 5 deletions(-)

New commits:
commit 5bee6f7747c9ae232468e7c8a78e8c5bbd05188c
Author: Andras Timar <andras.timar at collabora.com>
Date:   Thu Feb 15 15:17:32 2018 +0100

    wsd: handle request for robots.txt
    
    Change-Id: Ib82db2ee8c878e6a61b62b49ceaeb72e2d05718d
    Reviewed-on: https://gerrit.libreoffice.org/49819
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>
    (cherry picked from commit 8aa4a5145cafb7579105caafee4c127c97a010a4)
    Reviewed-on: https://gerrit.libreoffice.org/50004
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/Makefile.am b/Makefile.am
index 199b73cb..e4c77325 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,8 +14,7 @@ dist_doc_DATA = wsd/README \
 loolwsddatadir = @LOOLWSD_DATADIR@
 
 loolwsddata_DATA = discovery.xml \
-                   favicon.ico \
-                   robots.txt
+                   favicon.ico
 
 loolwsdconfigdir = @LOOLWSD_CONFIGDIR@
 
@@ -209,7 +208,6 @@ EXTRA_DIST = discovery.xml \
              loolwsd.spec \
              loolwsd.xml.in \
              loolwsd.service \
-             robots.txt \
              sysconfig.loolwsd \
              debian/compat \
              debian/copyright \
diff --git a/robots.txt b/robots.txt
deleted file mode 100644
index 1f53798b..00000000
--- a/robots.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-User-agent: *
-Disallow: /
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 83c4b1c2..3425774a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1825,6 +1825,10 @@ private:
             {
                 handleWopiDiscoveryRequest(request);
             }
+            else if (request.getMethod() == HTTPRequest::HTTP_GET && request.getURI() == "/robots.txt")
+            {
+                handleRobotsTxtRequest(request);
+            }
             else
             {
                 StringTokenizer reqPathTokens(request.getURI(), "/?", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
@@ -1960,6 +1964,31 @@ private:
         LOG_INF("Sent discovery.xml successfully.");
     }
 
+    void handleRobotsTxtRequest(const Poco::Net::HTTPRequest& request)
+    {
+        LOG_DBG("HTTP request: " << request.getURI());
+        const std::string mimeType = "text/plain";
+        const std::string responseString = "User-agent: *\nDisallow: /\n";
+
+        std::ostringstream oss;
+        oss << "HTTP/1.1 200 OK\r\n"
+            << "Last-Modified: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+            << "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
+            << "Content-Length: " << responseString.size() << "\r\n"
+            << "Content-Type: " << mimeType << "\r\n"
+            << "\r\n";
+
+        if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
+        {
+            oss << responseString;
+        }
+
+        std::shared_ptr<StreamSocket> socket = _socket.lock();
+        socket->send(oss.str());
+        socket->shutdown();
+        LOG_INF("Sent robots.txt response successfully.");
+    }
+
     static std::string getContentType(const std::string& fileName)
     {
         const std::string nodePath = Poco::format("//[@ext='%s']", Poco::Path(fileName).getExtension());


More information about the Libreoffice-commits mailing list