summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2014-12-10 19:13:21 +1100
committerLeith Bade <leith@mapbox.com>2014-12-10 19:13:21 +1100
commit69cd7268d783a5e449de38ab40dfe5a28fa76f64 (patch)
treea4951f03d039c2775317678d66afb0e61eb2f1ea /platform
parentc55cd7f473ca532193697882c48436d2f98885d2 (diff)
parent318ef5d44314814f4dd7da2ba8c532b0119bdb35 (diff)
downloadqtlocation-mapboxgl-69cd7268d783a5e449de38ab40dfe5a28fa76f64.tar.gz
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts: platform/default/http_request_baton_curl.cpp
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/http_request_baton_cocoa.mm13
-rw-r--r--platform/default/http_request_baton_curl.cpp18
2 files changed, 31 insertions, 0 deletions
diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm
index 472154dc2f..4a59837e32 100644
--- a/platform/darwin/http_request_baton_cocoa.mm
+++ b/platform/darwin/http_request_baton_cocoa.mm
@@ -2,6 +2,7 @@
#include <mbgl/util/std.hpp>
#include <mbgl/util/parsedate.h>
#include <mbgl/util/time.hpp>
+#include <mbgl/util/version.hpp>
#include <uv.h>
@@ -14,6 +15,8 @@ namespace mbgl {
dispatch_once_t request_initialize = 0;
NSURLSession *session = nullptr;
+NSString *userAgent = nil;
+
void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) {
assert(std::this_thread::get_id() == ptr->threadId);
@@ -28,6 +31,14 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) {
sessionConfig.URLCache = nil;
session = [NSURLSession sessionWithConfiguration:sessionConfig];
+
+ // Write user agent string
+ NSDictionary *systemVersion = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
+ userAgent = [NSString stringWithFormat:@"MapboxGL/%d.%d.%d (+https://mapbox.com/mapbox-gl/; %s; %@ %@)",
+ version::major, version::minor, version::patch, version::revision,
+ [systemVersion objectForKey:@"ProductName"],
+ [systemVersion objectForKey:@"ProductVersion"]
+ ];
});
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@(baton->path.c_str())]];
@@ -40,6 +51,8 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) {
}
}
+ [request addValue:userAgent forHTTPHeaderField:@"User-Agent"];
+
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *res, NSError *error) {
if (error) {
diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp
index 74c6187e76..9e8cf64716 100644
--- a/platform/default/http_request_baton_curl.cpp
+++ b/platform/default/http_request_baton_curl.cpp
@@ -4,6 +4,7 @@
#include <mbgl/util/time.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/std.hpp>
+#include <mbgl/util/version.hpp>
#ifdef __ANDROID__
#include <mbgl/android/jni.hpp>
@@ -14,6 +15,8 @@
#include <uv.h>
#include <curl/curl.h>
+#include <sys/utsname.h>
+
#include <queue>
#include <cassert>
#include <cstring>
@@ -509,9 +512,22 @@ static CURLcode sslctx_function(CURL */*curl*/, void *sslctx, void */*parm*/) {
}
#endif
+std::string buildUserAgentString() {
+#ifdef __ANDROID__
+ return util::sprintf<128>("MapboxGL/%d.%d.%d (+https://mapbox.com/mapbox-gl/; %s; %s %s)",
+ version::major, version::minor, version::patch, version::revision, "Android", mbgl::android::androidRelease.c_str());
+#else
+ utsname name;
+ uname(&name);
+ return util::sprintf<128>("MapboxGL/%d.%d.%d (+https://mapbox.com/mapbox-gl/; %s; %s %s)",
+ version::major, version::minor, version::patch, version::revision, name.sysname, name.release);
+#endif
+}
+
// This function must run in the CURL thread.
void start_request(void *const ptr) {
assert(std::this_thread::get_id() == thread_id);
+ static const std::string userAgent = buildUserAgentString();
// The Context object stores information that we need to retain throughout the request, such
// as the actual CURL easy handle, the baton, and the list of headers. The Context itself is
@@ -553,6 +569,8 @@ void start_request(void *const ptr) {
curl_easy_setopt(context->handle, CURLOPT_HEADERFUNCTION, curl_header_cb);
curl_easy_setopt(context->handle, CURLOPT_HEADERDATA, &context->baton->response);
curl_easy_setopt(context->handle, CURLOPT_ACCEPT_ENCODING, "gzip, deflate");
+ curl_easy_setopt(context->handle, CURLOPT_USERAGENT, userAgent.c_str());
+ curl_easy_setopt(context->handle, CURLOPT_SHARE, share);
// Start requesting the information.
curl_multi_add_handle(multi, context->handle);