#include <atomic>
#include <chrono>
#include <cstring>
#include <thread>
Go to the source code of this file.
◆ DART_EXPORT
#define DART_EXPORT extern "C" __attribute__((visibility("default"))) __attribute((used)) |
Definition at line 13 of file fake_http.cc.
19 : www.example.com
20)";
21
22constexpr char kExampleResponse[] = R"(
23HTTP/1.1 200 OK
24Content-Length: 54
25Content-
Type:
text/html; charset=UTF-8
26
27<html>
28 <body>
29 Hello world!
30 </body>
31</html>
32)";
33
34DART_EXPORT void http_get(const char* uri, void (*onResponse)(const char*)) {
35 std::thread([onResponse]() {
36 std::this_thread::sleep_for(std::chrono::seconds(3));
37 onResponse(strdup(kExampleResponse));
38 }).detach();
39}
40
41DART_EXPORT void http_serve(void (*onRequest)(const char*)) {
42 std::thread([onRequest]() {
43 while (true) {
44 std::this_thread::sleep_for(std::chrono::seconds(1));
45 onRequest(strdup(kExampleRequest));
46 }
47 }).detach();
48}
◆ http_get()
DART_EXPORT void http_get |
( |
const char * |
uri, |
|
|
void(*)(const char *) |
onResponse |
|
) |
| |
Definition at line 34 of file fake_http.cc.
34 {
35 std::thread([onResponse]() {
36 std::this_thread::sleep_for(std::chrono::seconds(3));
38 }).detach();
39}
constexpr char kExampleResponse[]
char * strdup(const char *str1)
◆ http_serve()
DART_EXPORT void http_serve |
( |
void(*)(const char *) |
onRequest | ) |
|
Definition at line 41 of file fake_http.cc.
41 {
42 std::thread([onRequest]() {
43 while (true) {
44 std::this_thread::sleep_for(std::chrono::seconds(1));
46 }
47 }).detach();
48}
constexpr char kExampleRequest[]
◆ kExampleRequest
constexpr char kExampleRequest[] |
|
constexpr |
Initial value:= R"(
GET / HTTP/1.1
Host: www.example.com
)"
Definition at line 17 of file fake_http.cc.
◆ kExampleResponse
constexpr char kExampleResponse[] |
|
constexpr |
Initial value:= R"(
HTTP/1.1 200 OK
Content-Length: 54
Content-Type: text/html; charset=UTF-8
<html>
<body>
Hello world!
</body>
</html>
)"
Definition at line 22 of file fake_http.cc.