Merge pull request #45 from kasper-f/fixImageLoading

Fixed #28 "Build status icon toggling"
This commit is contained in:
bassrock 2015-01-26 13:31:09 -08:00
commit 3ded0d61cd
1 changed files with 9 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import hudson.security.ACL;
import hudson.security.csrf.CrumbExclusion; import hudson.security.csrf.CrumbExclusion;
import hudson.util.HttpResponses; import hudson.util.HttpResponses;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
@ -267,9 +268,14 @@ public class GitLabWebHook implements UnprotectedRootAction {
Authentication old = SecurityContextHolder.getContext().getAuthentication(); Authentication old = SecurityContextHolder.getContext().getAuthentication();
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM); SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
try { try {
URL resourceUrl = new URL(Jenkins.getInstance().getPlugin("gitlab-plugin").getWrapper().baseResourceURL + imageUrl); URL resourceUrl = new URL(Jenkins.getInstance().getPlugin("gitlab-plugin").getWrapper().baseResourceURL + imageUrl);
rsp.serveFile(req, resourceUrl); LOGGER.info("serving image "+resourceUrl.toExternalForm());
} catch (IOException e) { rsp.setHeader("Expires","Fri, 01 Jan 1984 00:00:00 GMT");
rsp.setHeader("Cache-Control", "no-cache, private");
rsp.setHeader("Content-Type", "image/png");
hudson.util.IOUtils.copy(new File(resourceUrl.toURI()), rsp.getOutputStream());
rsp.flushBuffer();
} catch (Exception e) {
throw HttpResponses.error(500,"Could not generate response."); throw HttpResponses.error(500,"Could not generate response.");
} finally { } finally {
SecurityContextHolder.getContext().setAuthentication(old); SecurityContextHolder.getContext().setAuthentication(old);