aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.server
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.http.server')
-rw-r--r--org.eclipse.jgit.http.server/META-INF/MANIFEST.MF26
-rw-r--r--org.eclipse.jgit.http.server/pom.xml2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java17
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java18
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java44
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java7
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java23
7 files changed, 99 insertions, 38 deletions
diff --git a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
index 73e41e6b08..5791319c07 100644
--- a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
@@ -2,23 +2,23 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Bundle-SymbolicName: org.eclipse.jgit.http.server
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 1.3.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Export-Package:
- org.eclipse.jgit.http.server;version="1.2.0",
- org.eclipse.jgit.http.server.glue;version="1.2.0",
- org.eclipse.jgit.http.server.resolver;version="1.2.0"
+ org.eclipse.jgit.http.server;version="1.3.0",
+ org.eclipse.jgit.http.server.glue;version="1.3.0",
+ org.eclipse.jgit.http.server.resolver;version="1.3.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
javax.servlet.http;version="[2.5.0,3.0.0)",
- org.eclipse.jgit.errors;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.lib;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.nls;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.revwalk;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.storage.file;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.transport;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.transport.resolver;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.util;version="[1.2.0,1.3.0)",
- org.eclipse.jgit.util.io;version="[1.2.0,1.3.0)"
+ org.eclipse.jgit.errors;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.lib;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.nls;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.revwalk;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.storage.file;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.transport;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.transport.resolver;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.util;version="[1.3.0,1.4.0)",
+ org.eclipse.jgit.util.io;version="[1.3.0,1.4.0)"
diff --git a/org.eclipse.jgit.http.server/pom.xml b/org.eclipse.jgit.http.server/pom.xml
index 413d5d93f0..d4fc39eff7 100644
--- a/org.eclipse.jgit.http.server/pom.xml
+++ b/org.eclipse.jgit.http.server/pom.xml
@@ -52,7 +52,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.http.server</artifactId>
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java
index 3d2aff174d..8bd1704bc4 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitSmartHttpTools.java
@@ -49,11 +49,11 @@ import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -184,24 +184,27 @@ public class GitSmartHttpTools {
pck.writeString("# service=" + svc + "\n");
pck.end();
pck.writeString("ERR " + textForGit);
- send(res, infoRefsResultType(svc), buf.toByteArray());
+ send(req, res, infoRefsResultType(svc), buf.toByteArray());
} else if (isUploadPack(req)) {
pck.writeString("ERR " + textForGit);
- send(res, UPLOAD_PACK_RESULT_TYPE, buf.toByteArray());
+ send(req, res, UPLOAD_PACK_RESULT_TYPE, buf.toByteArray());
} else if (isReceivePack(req)) {
pck.writeString("ERR " + textForGit);
- send(res, RECEIVE_PACK_RESULT_TYPE, buf.toByteArray());
+ send(req, res, RECEIVE_PACK_RESULT_TYPE, buf.toByteArray());
} else {
+ if (httpStatus < 400)
+ ServletUtils.consumeRequestBody(req);
res.sendError(httpStatus);
}
}
- private static void send(HttpServletResponse res, String type, byte[] buf)
- throws IOException {
+ private static void send(HttpServletRequest req, HttpServletResponse res,
+ String type, byte[] buf) throws IOException {
+ ServletUtils.consumeRequestBody(req);
res.setStatus(HttpServletResponse.SC_OK);
res.setContentType(type);
res.setContentLength(buf.length);
- ServletOutputStream os = res.getOutputStream();
+ OutputStream os = res.getOutputStream();
try {
os.write(buf);
} finally {
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
index 6af28ba0d3..c84d52b695 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
@@ -52,6 +52,7 @@ import static org.eclipse.jgit.http.server.GitSmartHttpTools.RECEIVE_PACK_REQUES
import static org.eclipse.jgit.http.server.GitSmartHttpTools.RECEIVE_PACK_RESULT_TYPE;
import static org.eclipse.jgit.http.server.GitSmartHttpTools.sendError;
import static org.eclipse.jgit.http.server.ServletUtils.ATTRIBUTE_HANDLER;
+import static org.eclipse.jgit.http.server.ServletUtils.consumeRequestBody;
import static org.eclipse.jgit.http.server.ServletUtils.getInputStream;
import static org.eclipse.jgit.http.server.ServletUtils.getRepository;
@@ -158,17 +159,18 @@ class ReceivePackServlet extends HttpServlet {
return;
}
+ SmartOutputStream out = new SmartOutputStream(req, rsp) {
+ @Override
+ public void flush() throws IOException {
+ doFlush();
+ }
+ };
+
ReceivePack rp = (ReceivePack) req.getAttribute(ATTRIBUTE_HANDLER);
try {
rp.setBiDirectionalPipe(false);
rsp.setContentType(RECEIVE_PACK_RESULT_TYPE);
- final SmartOutputStream out = new SmartOutputStream(req, rsp) {
- @Override
- public void flush() throws IOException {
- doFlush();
- }
- };
rp.receive(getInputStream(req), out, null);
out.close();
} catch (UnpackException e) {
@@ -176,8 +178,10 @@ class ReceivePackServlet extends HttpServlet {
getServletContext().log(
HttpServerText.get().internalErrorDuringReceivePack,
e.getCause());
+ consumeRequestBody(req);
+ out.close();
- } catch (IOException e) {
+ } catch (Throwable e) {
getServletContext().log(HttpServerText.get().internalErrorDuringReceivePack, e);
if (!rsp.isCommitted()) {
rsp.reset();
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
index 2114655875..91fb8cce9a 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
@@ -119,6 +119,50 @@ public final class ServletUtils {
}
/**
+ * Consume the entire request body, if one was supplied.
+ *
+ * @param req
+ * the request whose body must be consumed.
+ */
+ public static void consumeRequestBody(HttpServletRequest req) {
+ if (0 < req.getContentLength() || isChunked(req)) {
+ try {
+ consumeRequestBody(req.getInputStream());
+ } catch (IOException e) {
+ // Ignore any errors obtaining the input stream.
+ }
+ }
+ }
+
+ private static boolean isChunked(HttpServletRequest req) {
+ return "chunked".equals(req.getHeader("Transfer-Encoding"));
+ }
+
+ /**
+ * Consume the rest of the input stream and discard it.
+ *
+ * @param in
+ * the stream to discard, closed if not null.
+ */
+ public static void consumeRequestBody(InputStream in) {
+ if (in == null)
+ return;
+ try {
+ while (0 < in.skip(2048) || 0 <= in.read()) {
+ // Discard until EOF.
+ }
+ } catch (IOException err) {
+ // Discard IOException during read or skip.
+ } finally {
+ try {
+ in.close();
+ } catch (IOException err) {
+ // Discard IOException during close of input stream.
+ }
+ }
+ }
+
+ /**
* Send a plain text response to a {@code GET} or {@code HEAD} HTTP request.
* <p>
* The text response is encoded in the Git character encoding, UTF-8.
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
index 00cb67ca95..c39b78900d 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
@@ -101,8 +101,11 @@ class SmartOutputStream extends TemporaryBuffer {
TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT);
try {
GZIPOutputStream gzip = new GZIPOutputStream(gzbuf);
- out.writeTo(gzip, null);
- gzip.close();
+ try {
+ out.writeTo(gzip, null);
+ } finally {
+ gzip.close();
+ }
if (gzbuf.length() < out.length()) {
out = gzbuf;
rsp.setHeader(HDR_CONTENT_ENCODING, ENCODING_GZIP);
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
index c7891dfc77..15ef2c7eac 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
@@ -52,6 +52,7 @@ import static org.eclipse.jgit.http.server.GitSmartHttpTools.UPLOAD_PACK_REQUEST
import static org.eclipse.jgit.http.server.GitSmartHttpTools.UPLOAD_PACK_RESULT_TYPE;
import static org.eclipse.jgit.http.server.GitSmartHttpTools.sendError;
import static org.eclipse.jgit.http.server.ServletUtils.ATTRIBUTE_HANDLER;
+import static org.eclipse.jgit.http.server.ServletUtils.consumeRequestBody;
import static org.eclipse.jgit.http.server.ServletUtils.getInputStream;
import static org.eclipse.jgit.http.server.ServletUtils.getRepository;
@@ -160,22 +161,26 @@ class UploadPackServlet extends HttpServlet {
return;
}
+ SmartOutputStream out = new SmartOutputStream(req, rsp) {
+ @Override
+ public void flush() throws IOException {
+ doFlush();
+ }
+ };
+
UploadPack up = (UploadPack) req.getAttribute(ATTRIBUTE_HANDLER);
try {
up.setBiDirectionalPipe(false);
rsp.setContentType(UPLOAD_PACK_RESULT_TYPE);
- final SmartOutputStream out = new SmartOutputStream(req, rsp) {
- @Override
- public void flush() throws IOException {
- doFlush();
- }
- };
up.upload(getInputStream(req), out, null);
out.close();
} catch (UploadPackMayNotContinueException e) {
- if (!e.isOutput() && !rsp.isCommitted()) {
+ if (e.isOutput()) {
+ consumeRequestBody(req);
+ out.close();
+ } else if (!rsp.isCommitted()) {
rsp.reset();
sendError(req, rsp, SC_FORBIDDEN, e.getMessage());
}
@@ -186,8 +191,10 @@ class UploadPackServlet extends HttpServlet {
getServletContext().log(
HttpServerText.get().internalErrorDuringUploadPack,
e.getCause());
+ consumeRequestBody(req);
+ out.close();
- } catch (IOException e) {
+ } catch (Throwable e) {
getServletContext().log(HttpServerText.get().internalErrorDuringUploadPack, e);
if (!rsp.isCommitted()) {
rsp.reset();