From 1f91be988bbc0ad01ac2cf5df496ce7e6a90ea32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 8 Dec 2014 10:56:00 +0100 Subject: add user agent header fixes #628 --- include/mbgl/util/constants.hpp | 32 ++++++++++++++++++++++++++++ platform/darwin/http_request_baton_cocoa.mm | 3 +++ platform/default/http_request_baton_curl.cpp | 2 ++ src/mbgl/util/constants.cpp | 1 + src/mbgl/util/constants.hpp | 31 --------------------------- 5 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 include/mbgl/util/constants.hpp delete mode 100644 src/mbgl/util/constants.hpp diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp new file mode 100644 index 0000000000..2270f53072 --- /dev/null +++ b/include/mbgl/util/constants.hpp @@ -0,0 +1,32 @@ +#ifndef MBGL_UTIL_CONSTANTS +#define MBGL_UTIL_CONSTANTS + +#include + +namespace mbgl { + +namespace util { + +extern const float tileSize; +extern const char *userAgent; + +} + +namespace debug { + +extern const bool tileParseWarnings; +extern const bool styleParseWarnings; +extern const bool spriteWarnings; +extern const bool renderWarnings; +extern const bool renderTree; +extern const bool labelTextMissingWarning; +extern const bool missingFontStackWarning; +extern const bool missingFontFaceWarning; +extern const bool glyphWarning; +extern const bool shapingWarning; + +} + +} + +#endif diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm index 1c256d0ba8..4030138970 100644 --- a/platform/darwin/http_request_baton_cocoa.mm +++ b/platform/darwin/http_request_baton_cocoa.mm @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -40,6 +41,8 @@ void HTTPRequestBaton::start(const util::ptr &ptr) { } } + [request addValue:@(util::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 f05ee5acf9..42915d3e79 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -444,6 +445,7 @@ 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, util::userAgent); curl_easy_setopt(context->handle, CURLOPT_SHARE, share); // Start requesting the information. diff --git a/src/mbgl/util/constants.cpp b/src/mbgl/util/constants.cpp index 3d1422e6c7..c37bc14801 100644 --- a/src/mbgl/util/constants.cpp +++ b/src/mbgl/util/constants.cpp @@ -1,6 +1,7 @@ #include const float mbgl::util::tileSize = 512.0f; +const char *mbgl::util::userAgent = "MapboxGL/1.0 (+https://mapbox.com/mapbox-gl/)"; #if defined(DEBUG) const bool mbgl::debug::tileParseWarnings = false; diff --git a/src/mbgl/util/constants.hpp b/src/mbgl/util/constants.hpp deleted file mode 100644 index 98365e0f32..0000000000 --- a/src/mbgl/util/constants.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MBGL_UTIL_CONSTANTS -#define MBGL_UTIL_CONSTANTS - -#include - -namespace mbgl { - -namespace util { - -extern const float tileSize; - -} - -namespace debug { - -extern const bool tileParseWarnings; -extern const bool styleParseWarnings; -extern const bool spriteWarnings; -extern const bool renderWarnings; -extern const bool renderTree; -extern const bool labelTextMissingWarning; -extern const bool missingFontStackWarning; -extern const bool missingFontFaceWarning; -extern const bool glyphWarning; -extern const bool shapingWarning; - -} - -} - -#endif -- cgit v1.2.1