Skip to content

Commit

Permalink
[JENKINS-19456] Improved sending response codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedam committed Sep 9, 2013
1 parent 531785f commit db52e3a
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -33,6 +33,7 @@
import java.util.zip.ZipFile;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.plexus.util.StringUtils;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -157,25 +158,25 @@ public void doDynamic(StaplerRequest req, StaplerResponse resp) throws IOExcepti
AbstractBuild<?,?> build = getBuild(req);
if (build == null) {
LOGGER.warning(String.format("No build found for url %s", req.getRequestURI()));
resp.sendError(404);
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}

File artifact = new File(build.getArtifactsDir(), getArtifactName());
if (!artifact.exists()) {
LOGGER.warning(String.format("Artifact does not exists: %s for %s", getArtifactName(), build.getFullDisplayName()));
resp.sendError(404);
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (!artifact.isFile()) {
LOGGER.warning(String.format("Artifact is not a file: %s for %s", getArtifactName(), build.getFullDisplayName()));
resp.sendError(403);
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}

if (req.getDateHeader("If-Modified-Since") >= 0) {
if (req.getDateHeader("If-Modified-Since") >= artifact.lastModified()) {
resp.sendError(304);
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
}
Expand All @@ -193,7 +194,7 @@ public void doDynamic(StaplerRequest req, StaplerResponse resp) throws IOExcepti
zip = new ZipFile(artifact);
} catch (ZipException e) {
LOGGER.warning(String.format("Artifact is not a zip file: %s for %s", getArtifactName(), build.getFullDisplayName()));
resp.sendError(403);
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}

Expand All @@ -206,7 +207,7 @@ public void doDynamic(StaplerRequest req, StaplerResponse resp) throws IOExcepti

ZipEntry entry = getFileEntry(zip, path);
if (entry == null) {
resp.sendError(404);
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}

Expand Down

0 comments on commit db52e3a

Please sign in to comment.