summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-01-06 12:26:54 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-01-12 12:01:24 -0800
commit5e33a1de831fcbac4ff53cadacfdfc8e7b204ffe (patch)
tree264a978001fbae0913eb0cd11da7cc71c2daec11 /org.eclipse.jgit
parent71b34847299f0c8f6923fe37fdd509f57fd35830 (diff)
downloadjgit-5e33a1de831fcbac4ff53cadacfdfc8e7b204ffe.tar.gz
jgit-5e33a1de831fcbac4ff53cadacfdfc8e7b204ffe.zip
Simple dumb HTTP server for Git
This is a simple HTTP server that provides the minimum server side support required for dumb (non-git aware) transport clients. We produce the info/refs and objects/info/packs file on the fly from the local repository state, but otherwise serve data as raw files from the on-disk structure. In the future we could better optimize the FileSender class and the servlets that use it to take advantage of direct file to network APIs in more advanced servlet containers like Jetty. Our glue package borrows the idea of a micro embedded DSL from Google Guice and uses it to configure a collection of Filters and HttpServlets, all of which are matched against requests using regular expressions. If a subgroup exists in the pattern, it is extracted and used for the path info component of the request. Change-Id: Ia0f1a425d07d035e344ae54faf8aeb04763e7487 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java32
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java19
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java58
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java39
4 files changed, 132 insertions, 16 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java
index d947a2cdc7..c745e7326e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009, Google Inc.
+ * Copyright (C) 2009-2010, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -64,8 +64,36 @@ public class RepositoryNotFoundException extends TransportException {
*
* @param location
* description of the repository not found, usually file path.
+ * @param why
+ * why the repository does not exist.
+ */
+ public RepositoryNotFoundException(final File location, Throwable why) {
+ this(location.getPath(), why);
+ }
+
+ /**
+ * Constructs an exception indicating a local repository does not exist.
+ *
+ * @param location
+ * description of the repository not found, usually file path.
*/
public RepositoryNotFoundException(final String location) {
- super("repository not found: " + location);
+ super(message(location));
+ }
+
+ /**
+ * Constructs an exception indicating a local repository does not exist.
+ *
+ * @param location
+ * description of the repository not found, usually file path.
+ * @param why
+ * why the repository does not exist.
+ */
+ public RepositoryNotFoundException(String location, Throwable why) {
+ super(message(location), why);
+ }
+
+ private static String message(final String location) {
+ return "repository not found: " + location;
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
index b6b9c5e05b..661371ca21 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2009, Constantine Plotnikov <constantine.plotnikov@gmail.com>
* Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
- * Copyright (C) 2008-2009, Google Inc.
+ * Copyright (C) 2008-2010, Google Inc.
* Copyright (C) 2009, Google, Inc.
* Copyright (C) 2009, JetBrains s.r.o.
* Copyright (C) 2007-2008, Robin Rosenberg <robin.rosenberg@dewire.com>
@@ -298,20 +298,11 @@ public class Config {
String n = getRawString(section, subsection, name);
if (n == null)
return defaultValue;
-
- if (MAGIC_EMPTY_VALUE == n || StringUtils.equalsIgnoreCase("yes", n)
- || StringUtils.equalsIgnoreCase("true", n)
- || StringUtils.equalsIgnoreCase("1", n)
- || StringUtils.equalsIgnoreCase("on", n)) {
+ if (MAGIC_EMPTY_VALUE == n)
return true;
-
- } else if (StringUtils.equalsIgnoreCase("no", n)
- || StringUtils.equalsIgnoreCase("false", n)
- || StringUtils.equalsIgnoreCase("0", n)
- || StringUtils.equalsIgnoreCase("off", n)) {
- return false;
-
- } else {
+ try {
+ return StringUtils.toBoolean(n);
+ } catch (IllegalArgumentException err) {
throw new IllegalArgumentException("Invalid boolean value: "
+ section + "." + name + "=" + n);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java
index 3910c8bd7f..8ce2ff06ec 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2010, Google Inc.
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
@@ -55,6 +56,63 @@ import java.net.URLEncoder;
/** Extra utilities to support usage of HTTP. */
public class HttpSupport {
+ /** The {@code POST} HTTP method. */
+ public static final String METHOD_POST = "POST";
+
+ /** The {@code Cache-Control} header. */
+ public static final String HDR_CACHE_CONTROL = "Cache-Control";
+
+ /** The {@code Pragma} header. */
+ public static final String HDR_PRAGMA = "Pragma";
+
+ /** The {@code Date} header. */
+ public static final String HDR_DATE = "Date";
+
+ /** The {@code Expires} header. */
+ public static final String HDR_EXPIRES = "Expires";
+
+ /** The {@code ETag} header. */
+ public static final String HDR_ETAG = "ETag";
+
+ /** The {@code If-None-Match} header. */
+ public static final String HDR_IF_NONE_MATCH = "If-None-Match";
+
+ /** The {@code Last-Modified} header. */
+ public static final String HDR_LAST_MODIFIED = "Last-Modified";
+
+ /** The {@code If-Modified-Since} header. */
+ public static final String HDR_IF_MODIFIED_SINCE = "If-Modified-Since";
+
+ /** The {@code Content-Type} header. */
+ public static final String HDR_CONTENT_TYPE = "Content-Type";
+
+ /** The {@code Content-Length} header. */
+ public static final String HDR_CONTENT_LENGTH = "Content-Length";
+
+ /** The {@code Content-Encoding} header. */
+ public static final String HDR_CONTENT_ENCODING = "Content-Encoding";
+
+ /** The {@code Content-Range} header. */
+ public static final String HDR_CONTENT_RANGE = "Content-Range";
+
+ /** The {@code Accept-Ranges} header. */
+ public static final String HDR_ACCEPT_RANGES = "Accept-Ranges";
+
+ /** The {@code If-Range} header. */
+ public static final String HDR_IF_RANGE = "If-Range";
+
+ /** The {@code Range} header. */
+ public static final String HDR_RANGE = "Range";
+
+ /** The {@code Accept-Encoding} header. */
+ public static final String HDR_ACCEPT_ENCODING = "Accept-Encoding";
+
+ /** The {@code gzip} encoding value for {@link #HDR_ACCEPT_ENCODING}. */
+ public static final String ENCODING_GZIP = "gzip";
+
+ /** The standard {@code text/plain} MIME type. */
+ public static final String TEXT_PLAIN = "text/plain";
+
/**
* URL encode a value string into an output buffer.
*
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java
index ddde48d6cf..582dce8aff 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java
@@ -115,6 +115,45 @@ public final class StringUtils {
return true;
}
+ /**
+ * Parse a string as a standard Git boolean value.
+ * <p>
+ * The terms {@code yes}, {@code true}, {@code 1}, {@code on} can all be
+ * used to mean {@code true}.
+ * <p>
+ * The terms {@code no}, {@code false}, {@code 0}, {@code off} can all be
+ * used to mean {@code false}.
+ * <p>
+ * Comparisons ignore case, via {@link #equalsIgnoreCase(String, String)}.
+ *
+ * @param stringValue
+ * the string to parse.
+ * @return the boolean interpretation of {@code value}.
+ * @throws IllegalArgumentException
+ * if {@code value} is not recognized as one of the standard
+ * boolean names.
+ */
+ public static boolean toBoolean(final String stringValue) {
+ if (stringValue == null)
+ throw new NullPointerException("Expected boolean string value");
+
+ if (equalsIgnoreCase("yes", stringValue)
+ || equalsIgnoreCase("true", stringValue)
+ || equalsIgnoreCase("1", stringValue)
+ || equalsIgnoreCase("on", stringValue)) {
+ return true;
+
+ } else if (equalsIgnoreCase("no", stringValue)
+ || equalsIgnoreCase("false", stringValue)
+ || equalsIgnoreCase("0", stringValue)
+ || equalsIgnoreCase("off", stringValue)) {
+ return false;
+
+ } else {
+ throw new IllegalArgumentException("Not a boolean: " + stringValue);
+ }
+ }
+
private StringUtils() {
// Do not create instances
}