OpsHandler.cpp 1.1 KB

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