Flutter Engine
The Flutter Engine
Response.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
11
12#include "include/core/SkData.h"
15
16#include "microhttpd.h"
17
18static DEFINE_string(source, "https://debugger-assets.skia.org", "Where to load the web UI from.");
19
21 SkString debuggerTemplate;
22 debuggerTemplate.appendf(
23 "<!DOCTYPE html>\n"
24 "<html>\n"
25 "<head>\n"
26 " <title>SkDebugger</title>\n"
27 " <meta charset='utf-8' />\n"
28 " <meta http-equiv='X-UA-Compatible' content='IE=edge'>\n"
29 " <meta name='viewport' content='width=device-width, initial-scale=1.0'>\n"
30 " <script src='%s/res/js/core.js' type='text/javascript' charset='utf-8'></script>\n"
31 " <link href='%s/res/vul/elements.html' rel='import' />\n"
32 " <link rel='shortcut icon' href='%s/res/img/favicon.ico' type='image/x-icon'/ >"
33 "</head>\n"
34 "<body class='fullbleed layout vertical'>\n"
35 " <debugger-app-sk>This is the app."
36 " </debugger-app-sk>\n"
37 "</body>\n"
38 "</html>", source.c_str(), source.c_str(), source.c_str());
39 return debuggerTemplate;
40}
41
42namespace Response {
43// SendOK just sends an empty response with a 200 OK status code.
44int SendOK(MHD_Connection* connection) {
45 const char* data = "";
46
47 MHD_Response* response = MHD_create_response_from_buffer(strlen(data),
48 (void*)data,
49 MHD_RESPMEM_PERSISTENT);
50 int ret = MHD_queue_response(connection, 200, response);
51 MHD_destroy_response(response);
52 return ret;
53}
54
55int SendError(MHD_Connection* connection, const char* msg) {
56 MHD_Response* response = MHD_create_response_from_buffer(strlen(msg),
57 (void*) msg,
58 MHD_RESPMEM_PERSISTENT);
59 int ret = MHD_queue_response(connection, 500, response);
60 MHD_destroy_response(response);
61 return ret;
62}
63
64int SendData(MHD_Connection* connection, const SkData* data, const char* type,
65 bool setContentDisposition, const char* dispositionString) {
66 MHD_Response* response = MHD_create_response_from_buffer(data->size(),
67 const_cast<void*>(data->data()),
68 MHD_RESPMEM_MUST_COPY);
69 MHD_add_response_header(response, "Content-Type", type);
70
71 if (setContentDisposition) {
72 MHD_add_response_header(response, "Content-Disposition", dispositionString);
73 }
74
75 int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
76 MHD_destroy_response(response);
77 return ret;
78}
79
80int SendTemplate(MHD_Connection* connection, bool redirect, const char* redirectUrl) {
81 SkString debuggerTemplate = generate_template(SkString(FLAGS_source[0]));
82
83 MHD_Response* response = MHD_create_response_from_buffer(
84 debuggerTemplate.size(),
85 (void*) const_cast<char*>(debuggerTemplate.c_str()),
86 MHD_RESPMEM_MUST_COPY);
87 MHD_add_response_header (response, "Access-Control-Allow-Origin", "*");
88
89 int status = MHD_HTTP_OK;
90
91 if (redirect) {
92 MHD_add_response_header (response, "Location", redirectUrl);
93 status = MHD_HTTP_SEE_OTHER;
94 }
95
96 int ret = MHD_queue_response(connection, status, response);
97 MHD_destroy_response(response);
98 return ret;
99}
100
101} // namespace Response
static DEFINE_string(source, "https://debugger-assets.skia.org", "Where to load the web UI from.")
static SkString generate_template(SkString source)
Definition: Response.cpp:20
GLenum type
Definition: SkData.h:25
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
SkBitmap source
Definition: examples.cpp:28
int SendData(MHD_Connection *connection, const SkData *data, const char *type, bool setContentDisposition, const char *dispositionString)
Definition: Response.cpp:64
int SendTemplate(MHD_Connection *connection, bool redirect, const char *redirectUrl)
Definition: Response.cpp:80
int SendOK(MHD_Connection *connection)
Definition: Response.cpp:44
int SendError(MHD_Connection *connection, const char *msg)
Definition: Response.cpp:55
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63