[PATCH] rhbz#678440: Always include User-Agent to avoid 403 from picky servers

Stephan Bergmann sbergman at redhat.com
Tue Jun 12 09:17:37 PDT 2012


(cherry picked from commit 4d0e3127ed2def7212bc05aa860cd06704bb1efe,
with modifications)

Change-Id: I4fa7b45062b0058427f77cf9dc0abebd6b26fb49
---
 ucb/source/ucp/webdav/DAVResourceAccess.cxx |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/ucb/source/ucp/webdav/DAVResourceAccess.cxx b/ucb/source/ucp/webdav/DAVResourceAccess.cxx
index 11b5251..f62ddaf 100644
--- a/ucb/source/ucp/webdav/DAVResourceAccess.cxx
+++ b/ucb/source/ucp/webdav/DAVResourceAccess.cxx
@@ -1151,6 +1151,24 @@ void DAVResourceAccess::getUserRequestHeaders(
             }
         }
     }
+
+    // Make sure a User-Agent header is always included, as at least
+    // en.wikipedia.org:80 forces back 403 "Scripts should use an informative
+    // User-Agent string with contact information, or they may be IP-blocked
+    // without notice" otherwise:
+    for ( DAVRequestHeaders::iterator i(rRequestHeaders.begin());
+          i != rRequestHeaders.end(); ++i )
+    {
+        if ( i->first.equalsIgnoreAsciiCaseAsciiL(
+                 RTL_CONSTASCII_STRINGPARAM( "User-Agent" ) ) )
+        {
+            return;
+        }
+    }
+    rRequestHeaders.push_back(
+        DAVRequestHeader(
+            rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "User-Agent" ) ),
+            rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LibreOffice" ) ) ) );
 }
 
 //=========================================================================
-- 
1.7.10.2


--------------040509060601030402000304--


More information about the LibreOffice mailing list