replace strftime_l with our custom formatter
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#ifndef MBGL_UTIL_TIME
|
||||
#define MBGL_UTIL_TIME
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -15,6 +17,10 @@ namespace util {
|
||||
// comparisons between different timestamps produce meaningful values.
|
||||
timestamp now();
|
||||
|
||||
|
||||
// Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT"
|
||||
std::string rfc1123(std::time_t time);
|
||||
|
||||
}
|
||||
|
||||
// used for time conversions
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <mbgl/util/uv-messenger.h>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
#include <curl/curl.h>
|
||||
@@ -9,8 +10,6 @@
|
||||
#include <queue>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <xlocale.h>
|
||||
|
||||
// This file contains code from http://curl.haxx.se/libcurl/c/multi-uv.html:
|
||||
|
||||
@@ -369,9 +368,6 @@ void start_request(void *const ptr) {
|
||||
util::ptr<HTTPRequestBaton> &baton = *baton_guard.get();
|
||||
assert(baton);
|
||||
|
||||
// Create a C locale
|
||||
static locale_t locale = newlocale(LC_ALL_MASK, nullptr, nullptr);
|
||||
|
||||
CURL *handle = nullptr;
|
||||
if (!handles.empty()) {
|
||||
handle = handles.front();
|
||||
@@ -390,11 +386,9 @@ void start_request(void *const ptr) {
|
||||
const std::string header = std::string("If-None-Match: ") + baton->response->etag;
|
||||
context->headers = curl_slist_append(context->headers, header.c_str());
|
||||
} else if (baton->response->modified) {
|
||||
const time_t modified = baton->response->modified;
|
||||
struct tm *timeinfo = std::gmtime(&modified);
|
||||
char buffer[64];
|
||||
strftime_l(buffer, 64, "If-Modified-Since: %a, %d %b %Y %H:%M:%S GMT", timeinfo, locale);
|
||||
context->headers = curl_slist_append(context->headers, buffer);
|
||||
const std::string time = std::string("If-Modified-Since: ") +
|
||||
util::rfc1123(baton->response->modified);
|
||||
context->headers = curl_slist_append(context->headers, time.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,5 +8,18 @@ timestamp now() {
|
||||
return uv_hrtime();
|
||||
}
|
||||
|
||||
static const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
std::string rfc1123(std::time_t time) {
|
||||
std::tm info;
|
||||
gmtime_r(&time, &info);
|
||||
char buffer[30];
|
||||
snprintf(buffer, 30, "%s, %02d %s %4d %02d:%02d:%02d GMT", week[info.tm_wday], info.tm_mday,
|
||||
months[info.tm_mon], 1900 + info.tm_year, info.tm_hour, info.tm_min, info.tm_sec);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user