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 "tools/skiaserve/urlhandlers/UrlHandler.h"
9 
10 #include "tools/skiaserve/Request.h"
11 #include "tools/skiaserve/Response.h"
12 #include "microhttpd.h"
13 
14 using namespace Response;
15 
canHandle(const char * method,const char * url)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 
handle(Request * request,MHD_Connection * connection,const char * url,const char * method,const char * upload_data,size_t * upload_data_size)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         sk_sp<SkData> data(request->getJsonOpsTask());
33         return SendData(connection, data.get(), "application/json");
34     }
35 
36     return MHD_NO;
37 }
38