Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason

Conflicts:
	platform/default/http_request_baton_curl.cpp
This commit is contained in:
Leith Bade
2014-12-10 19:13:21 +11:00
12 changed files with 164 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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);