blob: b37cd92beedc4d714ebc59907ac748e78a83266e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <mbgl/storage/http_request_baton.hpp>
#include <mbgl/storage/file_request_baton.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/url.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/platform/log.hpp>
#include <iostream>
#include <uv.h>
#include <cassert>
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
fn.erase(fn.find_last_of("/"));
fn.erase(fn.find_last_of("/"));
return fn + "/node_modules/mapbox-gl-test-suite/";
}();
namespace mbgl {
void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &baton) {
assert(uv_thread_self() == baton->thread_id);
std::string clean_url = util::percentDecode(baton->path);
if (clean_url.find("local://") == 0) {
clean_url = base_directory + clean_url.substr(8);
}
baton->response = std::make_unique<Response>();
FILE *file = fopen(clean_url.c_str(),"rb");
if (file != NULL) {
fseek(file, 0, SEEK_END);
const size_t size = ftell(file);
fseek(file, 0, SEEK_SET);
baton->response->data.resize(size);
fread(&baton->response->data[0], size, 1, file);
fclose(file);
baton->response->code = 200;
baton->type = HTTPResponseType::Successful;
} else {
baton->type = HTTPResponseType::PermanentError;
baton->response->code = 404;
}
uv_async_send(baton->async);
}
void HTTPRequestBaton::stop(const util::ptr<HTTPRequestBaton> &baton) {
fprintf(stderr, "HTTP request cannot be canceled because it is answered immediately");
abort();
}
namespace platform {
std::string defaultCacheDatabase() {
// Disables the cache.
return "";
}
}
}
|