comparison Core/HttpServer/HttpToolbox.cpp @ 1447:5ba7471780ae

refactoring: HttpToolbox, DumpJson in Lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 17:42:06 +0200
parents 8dc80ba768aa
children 3232f1c995a5
comparison
equal deleted inserted replaced
1446:8dc80ba768aa 1447:5ba7471780ae
192 compiled[source[i].first] = source[i].second; 192 compiled[source[i].first] = source[i].second;
193 } 193 }
194 } 194 }
195 195
196 196
197 bool HttpToolbox::SimpleGet(std::string& output, 197 bool HttpToolbox::SimpleGet(std::string& result,
198 IHttpHandler& handler, 198 IHttpHandler& handler,
199 const std::string& uri) 199 const std::string& uri)
200 { 200 {
201 IHttpHandler::Arguments headers; // No HTTP header 201 IHttpHandler::Arguments headers; // No HTTP header
202 202
208 HttpOutput http(stream, false /* no keep alive */); 208 HttpOutput http(stream, false /* no keep alive */);
209 209
210 if (handler.Handle(http, HttpMethod_Get, curi, headers, getArguments, 210 if (handler.Handle(http, HttpMethod_Get, curi, headers, getArguments,
211 NULL /* no body for GET */, 0)) 211 NULL /* no body for GET */, 0))
212 { 212 {
213 stream.GetOutput(output); 213 stream.GetOutput(result);
214 return true; 214 return true;
215 } 215 }
216 else 216 else
217 { 217 {
218 return false; 218 return false;
219 } 219 }
220 } 220 }
221 221
222
223 static bool SimplePostOrPut(std::string& result,
224 IHttpHandler& handler,
225 HttpMethod method,
226 const std::string& uri,
227 const char* bodyData,
228 size_t bodySize)
229 {
230 IHttpHandler::Arguments headers; // No HTTP header
231 IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT
232
233 UriComponents curi;
234 Toolbox::SplitUriComponents(curi, uri);
235
236 StringHttpOutput stream;
237 HttpOutput http(stream, false /* no keep alive */);
238
239 if (handler.Handle(http, method, curi, headers, getArguments, bodyData, bodySize))
240 {
241 stream.GetOutput(result);
242 return true;
243 }
244 else
245 {
246 return false;
247 }
248 }
249
250
251 bool HttpToolbox::SimplePost(std::string& result,
252 IHttpHandler& handler,
253 const std::string& uri,
254 const char* bodyData,
255 size_t bodySize)
256 {
257 return SimplePostOrPut(result, handler, HttpMethod_Post, uri, bodyData, bodySize);
258 }
259
260
261 bool HttpToolbox::SimplePut(std::string& result,
262 IHttpHandler& handler,
263 const std::string& uri,
264 const char* bodyData,
265 size_t bodySize)
266 {
267 return SimplePostOrPut(result, handler, HttpMethod_Put, uri, bodyData, bodySize);
268 }
269
270
271 bool HttpToolbox::SimpleDelete(IHttpHandler& handler,
272 const std::string& uri)
273 {
274 UriComponents curi;
275 Toolbox::SplitUriComponents(curi, uri);
276
277 IHttpHandler::Arguments headers; // No HTTP header
278 IHttpHandler::GetArguments getArguments; // No GET argument for DELETE
279
280 StringHttpOutput stream;
281 HttpOutput http(stream, false /* no keep alive */);
282
283 return handler.Handle(http, HttpMethod_Delete, curi, headers, getArguments,
284 NULL /* no body for DELETE */, 0);
285 }
222 } 286 }