MCPcopy Create free account
hub / github.com/acl-dev/acl / doApp

Method doApp

app/master/tools/master_dispatch/www/http_servlet.cpp:122–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122bool http_servlet::doApp(acl::HttpServletRequest& req,
123 acl::HttpServletResponse& res)
124{
125 acl::http_request* conn = (acl::http_request *) conns_->peek();
126 if (conn == NULL)
127 {
128 logger_error("no connection available, addr: %s",
129 var_cfg_manager_addr);
130 return doReply(req, res, 500, "%s", "no connection");
131 }
132
133 acl::http_header& hdr = conn->request_header();
134 hdr.set_url(var_cfg_access_url)
135 .set_keep_alive(true)
136 .set_method(acl::HTTP_METHOD_GET)
137 .accept_gzip(true);
138
139 if (conn->request(NULL, 0) == false)
140 {
141 logger_error("send request to %s error", var_cfg_manager_addr);
142 conns_->put(conn, false);
143 return doReply(req, res, 505, "%s", "send request error");
144 }
145
146 acl::xml1 xml;
147 char buf[8192];
148 while (true)
149 {
150 int ret = conn->read_body(buf, sizeof(buf) - 1);
151 if (ret == 0)
152 break;
153 else if (ret < 0)
154 {
155 conns_->put(conn, false);
156 logger_error("read_body error from %s",
157 var_cfg_manager_addr);
158 return doReply(req, res, 505, "%s", "read_body error");
159 }
160
161 buf[ret] = 0;
162 xml.update(buf);
163 }
164
165 conns_->put(conn, true);
166
167 acl::json json;
168 if (xmlToJson(xml, json) == false)
169 return doReply(req, res, 505, "%s", "invalid xml data");
170
171 return doReply(req, res, 200, json);
172}
173
174bool http_servlet::xmlToJson(acl::xml& xml, acl::json& json)
175{

Callers

nothing calls this directly

Calls 8

request_headerMethod · 0.80
accept_gzipMethod · 0.80
set_keep_aliveMethod · 0.80
peekMethod · 0.45
requestMethod · 0.45
putMethod · 0.45
read_bodyMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected