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 8 #include "UrlHandler.h" 9 10 #include "../Request.h" 11 #include "../Response.h" 12 #include "microhttpd.h" 13 14 using namespace Response; 15 16 bool OpsHandler::canHandle(const char* method, const char* url) { 17 const char* kBasePath = "/ops"; 18 return 0 == strncmp(url, kBasePath, strlen(kBasePath)); 19 } 20 21 int OpsHandler::handle(Request* request, MHD_Connection* connection, const char* url, 22 const char* method, const char* upload_data, size_t* upload_data_size) { 23 SkTArray<SkString> commands; 24 SkStrSplit(url, "/", &commands); 25 26 if (!request->hasPicture() || commands.count() > 1) { 27 return MHD_NO; 28 } 29 30 // /ops 31 if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { 32 int n = request->getLastOp(); 33 34 sk_sp<SkData> data(request->getJsonOpList(n)); 35 return SendData(connection, data.get(), "application/json"); 36 } 37 38 return MHD_NO; 39 } 40