Anonymous avatar Anonymous committed 2e532b6

#i21599# - Respect client-supplied User-Agent header values.

Comments (0)

Files changed (2)

ucb/source/ucp/webdav/NeonSession.cxx

         const DAVRequestHeaders & rHeaders
             = pSession->getRequestEnvironment().m_aRequestHeaders;
 
+        bool bHasUserAgent = false;
+
         DAVRequestHeaders::const_iterator it1( rHeaders.begin() );
         const DAVRequestHeaders::const_iterator end1( rHeaders.end() );
 
             ne_buffer_concat( headers, aHeader.getStr(), ": ",
                               aValue.getStr(), EOL, NULL );
 
+            if ( !bHasUserAgent &&
+                 (*it1).first.equalsIgnoreAsciiCaseAscii( "User-Agent" ) )
+                bHasUserAgent = true;
+
             ++it1;
         }
+
+        // Set User-Agent request header, if not already present.
+        // Note: We need per-request user agent; ne_set_useragent is not
+        // suitable, as it is per-session.
+        if ( !bHasUserAgent )
+            ne_buffer_concat( headers,
+                              "User-Agent: ",
+                              pSession->getUserAgent().getStr(), EOL, NULL );
     }
 }
 
 bool NeonSession::m_bGlobalsInited = false;
 osl::Mutex NeonSession::m_aGlobalMutex;
 NeonLockStore NeonSession::m_aNeonLockStore;
+rtl::OString NeonSession::m_aUserAgent;
 
 // -------------------------------------------------------------------
 // Constructor
                            // | NE_DBG_LOCKS
                          );
 #endif
+
+            // Calculate User-Agent request header value.
+            rtl::OUString aBootstrapConfigFile;
+            rtl::Bootstrap::get(
+                rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BRAND_BASE_DIR" ) ),
+                aBootstrapConfigFile );
+            aBootstrapConfigFile +=
+                rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+                    "/program/"SAL_CONFIGFILE( "bootstrap" ) ) );
+
+            rtl::Bootstrap aData( aBootstrapConfigFile );
+            rtl::OUString aProductKeyValue;
+            aData.getFrom(
+                rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ProductKey" ) ),
+                aProductKeyValue,
+                rtl::OUString() );
+
+            sal_Int32 n = aProductKeyValue.lastIndexOf( sal_Unicode( ' ' ) );
+            if ( n != -1 )
+                aProductKeyValue
+                    = aProductKeyValue.replaceAt(
+                        n, 1, rtl::OUString(
+                            RTL_CONSTASCII_USTRINGPARAM( "/" ) ) );
+
+            rtl::OString aUserAgent
+                = rtl::OUStringToOString( aProductKeyValue,
+                                          RTL_TEXTENCODING_UTF8 );
+
+            rtl::OString aNeonVersion( ne_version_string() );
+            n = aNeonVersion.indexOf( ':' );
+            if ( n != -1 )
+            {
+                aNeonVersion
+                    = aNeonVersion.replaceAt( 4, 1, rtl::OString( '/' ) );
+                aUserAgent += rtl::OString( ' ' );
+                aUserAgent += aNeonVersion.copy( 0, n );
+            }
+
+            m_aUserAgent = aUserAgent;
+
             m_bGlobalsInited = true;
         }
 
 
         m_pHttpSession = ne_session_create(
             rtl::OUStringToOString( m_aScheme,
-                RTL_TEXTENCODING_UTF8 ).getStr(),
+                                    RTL_TEXTENCODING_UTF8 ).getStr(),
             /* theUri.GetUserInfo(),
                @@@ for FTP via HTTP proxy, but not supported by Neon */
             rtl::OUStringToOString( m_aHostName,
             m_pHttpSession, NE_AUTH_ALL, NeonSession_NeonAuth, this );
         ne_add_proxy_auth(
             m_pHttpSession, NE_AUTH_ALL, NeonSession_NeonAuth, this );
-
-        // Set User-Agent request header
-        rtl::OUString aBootstrapConfigFile;
-        rtl::Bootstrap::get(
-            rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BRAND_BASE_DIR" ) ),
-            aBootstrapConfigFile );
-        aBootstrapConfigFile +=
-            rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
-               "/program/"SAL_CONFIGFILE( "bootstrap" ) ) );
-
-        rtl::Bootstrap aData( aBootstrapConfigFile );
-        rtl::OUString aProductKeyValue;
-        aData.getFrom(
-            rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ProductKey" ) ),
-            aProductKeyValue,
-            rtl::OUString() );
-
-        sal_Int32 n = aProductKeyValue.lastIndexOf( sal_Unicode( ' ' ) );
-        if ( n != -1 )
-            aProductKeyValue
-                = aProductKeyValue.replaceAt(
-                    n, 1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) );
-
-        ne_set_useragent( m_pHttpSession,
-                          rtl::OUStringToOString(
-                                  aProductKeyValue,
-                                  RTL_TEXTENCODING_UTF8 ).getStr() );
     }
 }
 
 }
 
 // -------------------------------------------------------------------
+const rtl::OString & NeonSession::getUserAgent()
+{
+    Init();
+    return m_aUserAgent;
+}
+
+// -------------------------------------------------------------------
 // OPTIONS
 // -------------------------------------------------------------------
 void NeonSession::OPTIONS( const rtl::OUString & inPath,

ucb/source/ucp/webdav/NeonSession.hxx

 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
     DAVRequestEnvironment m_aEnv;
 
     static bool          m_bGlobalsInited;
-    static osl::Mutex m_aGlobalMutex;
+    static osl::Mutex    m_aGlobalMutex;
     static NeonLockStore m_aNeonLockStore;
+    static rtl::OString  m_aUserAgent;
 
 protected:
     virtual ~NeonSession();
 
     sal_Bool isDomainMatch( rtl::OUString certHostName );
 
+    const rtl::OString & getUserAgent();
+
 private:
     friend class NeonLockStore;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.