[webtools] Header fixed about User-Agent
[scilab.git] / scilab / modules / webtools / src / cpp / sciCurl.cpp
index cb7601d..6b37004 100644 (file)
@@ -20,6 +20,8 @@ extern "C"
 {
     #include "getScilabPreference.h"
     #include "freeArrayOfString.h"
+    #include "getos.h"
+    #include "version.h"
 }
 
 SciCurl* SciCurl::me = nullptr;
@@ -176,3 +178,19 @@ int SciCurl::setProxy(CURL* curl)
     freeArrayOfString(values, N);
     return 0;
 }
+
+void SciCurl::setCommonHeaders(CURL* curl)
+{
+    char* OperatingSystem = getOSFullName();
+    char* Release = getOSRelease();
+
+    // Scilab version
+    std::string pcUserAgent = "Scilab/" + std::to_string(SCI_VERSION_MAJOR)+"."+ std::to_string(SCI_VERSION_MINOR)+"."+ std::to_string(SCI_VERSION_MAINTENANCE);
+    // OS name
+    pcUserAgent += " (" + std::string(OperatingSystem) + " " + std::string(Release) + ")";
+    // set user agent header
+    curl_easy_setopt(curl, CURLOPT_USERAGENT, pcUserAgent.data());
+
+    FREE(OperatingSystem);
+    FREE(Release);
+}
\ No newline at end of file