comparison Core/HttpServer/HttpToolbox.cpp @ 3442:dd1e68f2d0c0

Fix issue #106 (Unable to export preview as jpeg from Lua script)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 24 Jun 2019 16:06:47 +0200
parents 962e5f00744b
children 94f4a18a79cc
comparison
equal deleted inserted replaced
3441:6cc72ebfd6ef 3442:dd1e68f2d0c0
223 return false; 223 return false;
224 } 224 }
225 } 225 }
226 226
227 227
228 bool HttpToolbox::SimpleGet(std::string& result,
229 IHttpHandler& handler,
230 RequestOrigin origin,
231 const std::string& uri)
232 {
233 IHttpHandler::Arguments headers; // No HTTP header
234 return SimpleGet(result, handler, origin, uri, headers);
235 }
236
237
238 static bool SimplePostOrPut(std::string& result, 228 static bool SimplePostOrPut(std::string& result,
239 IHttpHandler& handler, 229 IHttpHandler& handler,
240 RequestOrigin origin, 230 RequestOrigin origin,
241 HttpMethod method, 231 HttpMethod method,
242 const std::string& uri, 232 const std::string& uri,
243 const void* bodyData, 233 const void* bodyData,
244 size_t bodySize) 234 size_t bodySize,
245 { 235 const IHttpHandler::Arguments& httpHeaders)
246 IHttpHandler::Arguments headers; // No HTTP header 236 {
247 IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT 237 IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT
248 238
249 UriComponents curi; 239 UriComponents curi;
250 Toolbox::SplitUriComponents(curi, uri); 240 Toolbox::SplitUriComponents(curi, uri);
251 241
252 StringHttpOutput stream; 242 StringHttpOutput stream;
253 HttpOutput http(stream, false /* no keep alive */); 243 HttpOutput http(stream, false /* no keep alive */);
254 244
255 if (handler.Handle(http, origin, LOCALHOST, "", method, curi, 245 if (handler.Handle(http, origin, LOCALHOST, "", method, curi,
256 headers, getArguments, bodyData, bodySize)) 246 httpHeaders, getArguments, bodyData, bodySize))
257 { 247 {
258 stream.GetOutput(result); 248 stream.GetOutput(result);
259 return true; 249 return true;
260 } 250 }
261 else 251 else
268 bool HttpToolbox::SimplePost(std::string& result, 258 bool HttpToolbox::SimplePost(std::string& result,
269 IHttpHandler& handler, 259 IHttpHandler& handler,
270 RequestOrigin origin, 260 RequestOrigin origin,
271 const std::string& uri, 261 const std::string& uri,
272 const void* bodyData, 262 const void* bodyData,
273 size_t bodySize) 263 size_t bodySize,
274 { 264 const IHttpHandler::Arguments& httpHeaders)
275 return SimplePostOrPut(result, handler, origin, HttpMethod_Post, uri, bodyData, bodySize); 265 {
266 return SimplePostOrPut(result, handler, origin, HttpMethod_Post, uri, bodyData, bodySize, httpHeaders);
276 } 267 }
277 268
278 269
279 bool HttpToolbox::SimplePut(std::string& result, 270 bool HttpToolbox::SimplePut(std::string& result,
280 IHttpHandler& handler, 271 IHttpHandler& handler,
281 RequestOrigin origin, 272 RequestOrigin origin,
282 const std::string& uri, 273 const std::string& uri,
283 const void* bodyData, 274 const void* bodyData,
284 size_t bodySize) 275 size_t bodySize,
285 { 276 const IHttpHandler::Arguments& httpHeaders)
286 return SimplePostOrPut(result, handler, origin, HttpMethod_Put, uri, bodyData, bodySize); 277 {
278 return SimplePostOrPut(result, handler, origin, HttpMethod_Put, uri, bodyData, bodySize, httpHeaders);
287 } 279 }
288 280
289 281
290 bool HttpToolbox::SimpleDelete(IHttpHandler& handler, 282 bool HttpToolbox::SimpleDelete(IHttpHandler& handler,
291 RequestOrigin origin, 283 RequestOrigin origin,
292 const std::string& uri) 284 const std::string& uri,
285 const IHttpHandler::Arguments& httpHeaders)
293 { 286 {
294 UriComponents curi; 287 UriComponents curi;
295 Toolbox::SplitUriComponents(curi, uri); 288 Toolbox::SplitUriComponents(curi, uri);
296 289
297 IHttpHandler::Arguments headers; // No HTTP header
298 IHttpHandler::GetArguments getArguments; // No GET argument for DELETE 290 IHttpHandler::GetArguments getArguments; // No GET argument for DELETE
299 291
300 StringHttpOutput stream; 292 StringHttpOutput stream;
301 HttpOutput http(stream, false /* no keep alive */); 293 HttpOutput http(stream, false /* no keep alive */);
302 294
303 return handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Delete, curi, 295 return handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Delete, curi,
304 headers, getArguments, NULL /* no body for DELETE */, 0); 296 httpHeaders, getArguments, NULL /* no body for DELETE */, 0);
305 } 297 }
306 } 298 }