Skia serve now supports favicon correctly

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1676403002

Review URL: https://codereview.chromium.org/1676403002
diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp
index a8ddcdf..e2e5450 100644
--- a/tools/skiaserve/skiaserve.cpp
+++ b/tools/skiaserve/skiaserve.cpp
@@ -29,6 +29,7 @@
 __SK_FORCE_IMAGE_DECODER_LINKING;
 
 DEFINE_string(source, "https://debugger.skia.org", "Where to load the web UI from.");
+DEFINE_string(faviconDir, "tools/skiaserve", "The directory of the favicon");
 DEFINE_int32(port, 8888, "The port to listen on.");
 
 // TODO probably want to make this configurable
@@ -443,6 +444,28 @@
     }
 };
 
+class FaviconHandler : public UrlHandler {
+public:
+    bool canHandle(const char* method, const char* url) override {
+        return 0 == strcmp(method, MHD_HTTP_METHOD_GET) &&
+               0 == strcmp(url, "/favicon.ico");
+    }
+
+    int handle(Request* request, MHD_Connection* connection,
+               const char* url, const char* method,
+               const char* upload_data, size_t* upload_data_size) override {
+        SkString dir(FLAGS_faviconDir[0]);
+        dir.append("/favicon.ico");
+        FILE* ico = fopen(dir.c_str(), "r");
+
+        SkAutoTUnref<SkData> data(SkData::NewFromFILE(ico));
+        int ret = SendData(connection, data, "image/vnd.microsoft.icon");
+        fclose(ico);
+        return ret;
+    }
+};
+
+
 class RootHandler : public UrlHandler {
 public:
     bool canHandle(const char* method, const char* url) override {
@@ -468,6 +491,7 @@
         fHandlers.push_back(new InfoHandler);
         fHandlers.push_back(new DownloadHandler);
         fHandlers.push_back(new DataHandler);
+        fHandlers.push_back(new FaviconHandler);
     }
 
     ~UrlManager() {
@@ -502,7 +526,7 @@
     int result = kUrlManager.invoke(request, connection, url, method, upload_data,
                                     upload_data_size);
     if (MHD_NO == result) {
-        fprintf(stderr, "Invalid method and / or url: %s %s)\n", method, url);
+        fprintf(stderr, "Invalid method and / or url: %s %s\n", method, url);
     }
     return result;
 }