Fix retrieval of path from URL

The ImageServlet needs the encoded URL path, but it used
HttpServletRequest.getPathInfo() to retrieve it which returns the
decoded path. So far this worked because there was a bug in Guice [1]
that made HttpServletRequest.getPathInfo() return the encoded path.
Now this bug was fixed in Guice and Gerrit was updated to use the new
Guice version. Hence the ImageServlet started to fail and needs to be
adapted.

[1] https://github.com/google/guice/issues/745

Change-Id: Ie44786acaa70b9612572727dad856d3fdcf472ae
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/imagare/ImageServlet.java b/src/main/java/com/googlesource/gerrit/plugins/imagare/ImageServlet.java
index b8093bd..4218fcc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/imagare/ImageServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/imagare/ImageServlet.java
@@ -20,13 +20,14 @@
 import com.google.common.base.CharMatcher;
 import com.google.common.hash.Hashing;
 import com.google.common.net.HttpHeaders;
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.restapi.AuthException;
 import com.google.gerrit.extensions.restapi.IdString;
 import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.reviewdb.server.ReviewDb;
-import com.google.gerrit.server.mime.FileTypeRegistry;
 import com.google.gerrit.server.git.GitRepositoryManager;
+import com.google.gerrit.server.mime.FileTypeRegistry;
 import com.google.gerrit.server.project.GetHead;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.project.ProjectCache;
@@ -38,6 +39,8 @@
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
 
+import eu.medsea.mimeutil.MimeType;
+
 import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.errors.RevisionSyntaxException;
 import org.eclipse.jgit.lib.Constants;
@@ -50,8 +53,6 @@
 import org.eclipse.jgit.treewalk.TreeWalk;
 import org.eclipse.jgit.treewalk.filter.PathFilter;
 
-import eu.medsea.mimeutil.MimeType;
-
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
 
@@ -65,6 +66,7 @@
 
   public  static final String PATH_PREFIX = "/project/";
 
+  private final String pluginName;
   private final Provider<ReviewDb> db;
   private final ProjectControl.Factory projectControlFactory;
   private final ProjectCache projectCache;
@@ -74,12 +76,14 @@
 
   @Inject
   ImageServlet(
+      @PluginName String pluginName,
       Provider<ReviewDb> db,
       ProjectControl.Factory projectControlFactory,
       ProjectCache projectCache,
       Provider<GetHead> getHead,
       GitRepositoryManager repoManager,
       FileTypeRegistry fileTypeRegistry) {
+    this.pluginName = pluginName;
     this.db = db;
     this.projectControlFactory = projectControlFactory;
     this.projectCache = projectCache;
@@ -97,7 +101,7 @@
       return;
     }
 
-    ResourceKey key = ResourceKey.fromPath(req.getPathInfo());
+    ResourceKey key = ResourceKey.fromPath(getEncodedPath(req));
     ProjectState state = projectCache.get(key.project);
     if (state == null || key.file == null) {
       notFound(res);
@@ -201,6 +205,15 @@
     }
   }
 
+  private String getEncodedPath(HttpServletRequest req) {
+    String path = req.getRequestURI();
+    String prefix = "/plugins/" + pluginName;
+    if (path.startsWith(prefix)) {
+      path = path.substring(prefix.length());
+    }
+    return path;
+  }
+
   private static String computeETag(Project.NameKey project, ObjectId revId,
       String file) {
     return Hashing.md5().newHasher()