Move user agent initialization to InitCurl_easy
Places that didn't initialize it previously, would benefit automatically Change-Id: I2f1ff25fc58d9378462072bc92d7b37be2370fc8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159299 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
parent
50add20437
commit
f5926c8cfb
11 changed files with 34 additions and 42 deletions
|
@ -38,7 +38,7 @@
|
|||
#include <orcus/config.hpp>
|
||||
#include <orcus/pstring.hpp>
|
||||
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
#include <comphelper/hash.hxx>
|
||||
|
||||
#include <com/sun/star/container/XNameAccess.hpp>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <memory>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
|
||||
#include <o3tl/string_view.hxx>
|
||||
#include <osl/diagnose.h>
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
#include "opensslinit.hxx"
|
||||
#endif
|
||||
|
||||
#include <rtl/string.hxx>
|
||||
#include <sal/log.hxx>
|
||||
|
||||
#include <config_version.h>
|
||||
|
||||
static void InitCurl_easy(CURL* const pCURL)
|
||||
{
|
||||
CURLcode rc;
|
||||
|
@ -44,6 +49,25 @@ static void InitCurl_easy(CURL* const pCURL)
|
|||
rc = curl_easy_setopt(pCURL, CURLOPT_REDIR_PROTOCOLS_STR, "https");
|
||||
assert(rc == CURLE_OK);
|
||||
}
|
||||
|
||||
curl_version_info_data const* const pVersion(curl_version_info(CURLVERSION_NOW));
|
||||
assert(pVersion);
|
||||
SAL_INFO("ucb.ucp.webdav.curl",
|
||||
"curl version: " << pVersion->version << " " << pVersion->host
|
||||
<< " features: " << ::std::hex << pVersion->features << " ssl: "
|
||||
<< pVersion->ssl_version << " libz: " << pVersion->libz_version);
|
||||
// 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:
|
||||
OString const useragent(
|
||||
OString::Concat("LibreOffice " LIBO_VERSION_DOTTED " denylistedbackend/")
|
||||
+ pVersion->version + " " + pVersion->ssl_version);
|
||||
// looks like an explicit "User-Agent" header in CURLOPT_HTTPHEADER
|
||||
// will override CURLOPT_USERAGENT, see Curl_http_useragent(), so no need
|
||||
// to check anything here
|
||||
rc = curl_easy_setopt(pCURL, CURLOPT_USERAGENT, useragent.getStr());
|
||||
assert(rc == CURLE_OK);
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
|
@ -42,7 +42,7 @@
|
|||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
|
||||
#include <sal/log.hxx>
|
||||
#include <tools/color.hxx>
|
||||
|
@ -135,14 +135,6 @@ std::string makeHttpRequest_impl(std::u16string_view aURL, HTTP_METHOD method,
|
|||
|
||||
::InitCurl_easy(curl.get());
|
||||
|
||||
// Same useragent string as in CurlSession (ucp/webdav-curl/CurlSession.cxx)
|
||||
curl_version_info_data const* const pVersion(curl_version_info(CURLVERSION_NOW));
|
||||
assert(pVersion);
|
||||
OString const useragent(
|
||||
OString::Concat("LibreOffice " LIBO_VERSION_DOTTED " denylistedbackend/")
|
||||
+ pVersion->version + " " + pVersion->ssl_version);
|
||||
(void)curl_easy_setopt(curl.get(), CURLOPT_USERAGENT, useragent.getStr());
|
||||
|
||||
OString aURL8 = OUStringToOString(aURL, RTL_TEXTENCODING_UTF8);
|
||||
(void)curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, pHttpHeader);
|
||||
(void)curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <rtl/string.h>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
#include <vcl/htmltransferable.hxx>
|
||||
#include <tools/long.hxx>
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <config_crypto.h>
|
||||
|
||||
#if USE_CRYPTO_NSS
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
#endif
|
||||
|
||||
#include <rtl/character.hxx>
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
#include <ucbhelper/proxydecider.hxx>
|
||||
#include <ucbhelper/macros.hxx>
|
||||
#include <sax/tools/converter.hxx>
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include <rtl/uri.hxx>
|
||||
#include <rtl/strbuf.hxx>
|
||||
#include <rtl/ustrbuf.hxx>
|
||||
#include <curlinit.hxx>
|
||||
#include <systools/curlinit.hxx>
|
||||
#include <config_version.h>
|
||||
|
||||
#include <map>
|
||||
|
@ -613,33 +613,9 @@ CurlSession::CurlSession(uno::Reference<uno::XComponentContext> xContext,
|
|||
throw DAVException(DAVException::DAV_SESSION_CREATE,
|
||||
ConnectionEndPointString(m_URI.GetHost(), m_URI.GetPort()));
|
||||
}
|
||||
curl_version_info_data const* const pVersion(curl_version_info(CURLVERSION_NOW));
|
||||
assert(pVersion);
|
||||
SAL_INFO("ucb.ucp.webdav.curl",
|
||||
"curl version: " << pVersion->version << " " << pVersion->host
|
||||
<< " features: " << ::std::hex << pVersion->features << " ssl: "
|
||||
<< pVersion->ssl_version << " libz: " << pVersion->libz_version);
|
||||
// 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:
|
||||
OString const useragent(
|
||||
OString::Concat("LibreOffice " LIBO_VERSION_DOTTED " denylistedbackend/")
|
||||
+ ::std::string_view(pVersion->version, strlen(pVersion->version)) + " "
|
||||
+ pVersion->ssl_version);
|
||||
// looks like an explicit "User-Agent" header in CURLOPT_HTTPHEADER
|
||||
// will override CURLOPT_USERAGENT, see Curl_http_useragent(), so no need
|
||||
// to check anything here
|
||||
auto rc = curl_easy_setopt(m_pCurl.get(), CURLOPT_USERAGENT, useragent.getStr());
|
||||
if (rc != CURLE_OK)
|
||||
{
|
||||
SAL_WARN("ucb.ucp.webdav.curl", "CURLOPT_USERAGENT failed: " << GetErrorString(rc));
|
||||
throw DAVException(DAVException::DAV_SESSION_CREATE,
|
||||
ConnectionEndPointString(m_URI.GetHost(), m_URI.GetPort()));
|
||||
}
|
||||
m_ErrorBuffer[0] = '\0';
|
||||
// this supposedly gives the highest quality error reporting
|
||||
rc = curl_easy_setopt(m_pCurl.get(), CURLOPT_ERRORBUFFER, m_ErrorBuffer);
|
||||
auto rc = curl_easy_setopt(m_pCurl.get(), CURLOPT_ERRORBUFFER, m_ErrorBuffer);
|
||||
assert(rc == CURLE_OK);
|
||||
#if 1
|
||||
// just for debugging...
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
|
||||
#include <config_features.h>
|
||||
#include <config_feature_opencl.h>
|
||||
#include <opensslinit.hxx>
|
||||
#include <systools/opensslinit.hxx>
|
||||
|
||||
#include <osl/process.h>
|
||||
#include <com/sun/star/lang/XComponent.hpp>
|
||||
|
|
Loading…
Reference in a new issue