diff --git a/build.xml b/build.xml
index 187359e..de766bd 100644
--- a/build.xml
+++ b/build.xml
@@ -46,7 +46,7 @@
+ includes="JettyLauncher.class,CustomConnector.class"/>
diff --git a/contrib/redhat/gitbucket.conf b/contrib/redhat/gitbucket.conf
index fb14ebe..c3959f3 100644
--- a/contrib/redhat/gitbucket.conf
+++ b/contrib/redhat/gitbucket.conf
@@ -1,6 +1,12 @@
+# Bind host
+#GITBUCKET_HOST=0.0.0.0
+
# Server port
#GITBUCKET_PORT=8080
+# Force HTTPS scheme
+#GITBUCKET_HTTPS=false
+
# Data directory (GITBUCKET_HOME/gitbucket)
#GITBUCKET_HOME=/var/lib/gitbucket
diff --git a/contrib/redhat/gitbucket.init b/contrib/redhat/gitbucket.init
index 6ab01f8..3aed802 100644
--- a/contrib/redhat/gitbucket.init
+++ b/contrib/redhat/gitbucket.init
@@ -12,7 +12,6 @@
. /etc/rc.d/init.d/functions
# Default values
-GITBUCKET_PORT=8080
GITBUCKET_HOME=/var/lib/gitbucket
GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war
@@ -31,9 +30,17 @@
echo -n $"Starting GitBucket server: "
# Compile statup parameters
- START_OPTS="--port=${GITBUCKET_PORT}"
+ if [ $GITBUCKET_PORT ]; then
+ START_OPTS="${START_OPTS} --port=${GITBUCKET_PORT}"
+ fi
if [ $GITBUCKET_PREFIX ]; then
- START_OPTS="${START_OPTS} --prefix ${GITBUCKET_PREFIX}"
+ START_OPTS="${START_OPTS} --prefix=${GITBUCKET_PREFIX}"
+ fi
+ if [ $GITBUCKET_HOST ]; then
+ START_OPTS="${START_OPTS} --host=${GITBUCKET_HOST}"
+ fi
+ if [ $GITBUCKET_HTTPS ]; then
+ START_OPTS="${START_OPTS} --https=true"
fi
# Run the Java process
diff --git a/src/main/java/JettyLauncher.java b/src/main/java/JettyLauncher.java
index 356da21..5edba71 100644
--- a/src/main/java/JettyLauncher.java
+++ b/src/main/java/JettyLauncher.java
@@ -1,7 +1,10 @@
+import org.eclipse.jetty.io.EndPoint;
+import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;
+import java.io.IOException;
import java.net.URL;
import java.security.ProtectionDomain;
@@ -10,17 +13,20 @@
String host = null;
int port = 8080;
String contextPath = "/";
+ boolean forceHttps = false;
- for(String arg: args){
- if(arg.startsWith("--") && arg.contains("=")){
+ for(String arg: args) {
+ if(arg.startsWith("--") && arg.contains("=")) {
String[] dim = arg.split("=");
- if(dim.length >= 2){
- if(dim[0].equals("--host")){
+ if(dim.length >= 2) {
+ if(dim[0].equals("--host")) {
host = dim[1];
- } else if(dim[0].equals("--port")){
+ } else if(dim[0].equals("--port")) {
port = Integer.parseInt(dim[1]);
- } else if(dim[0].equals("--prefix")){
+ } else if(dim[0].equals("--prefix")) {
contextPath = dim[1];
+ } else if(dim[0].equals("--https") && (dim[1].equals("1") || dim[1].equals("true"))) {
+ forceHttps = true;
}
}
}
@@ -28,8 +34,8 @@
Server server = new Server();
- SelectChannelConnector connector = new SelectChannelConnector();
- if(host != null){
+ CustomConnector connector = new CustomConnector(forceHttps);
+ if(host != null) {
connector.setHost(host);
}
connector.setMaxIdleTime(1000 * 60 * 60);
@@ -51,3 +57,19 @@
server.join();
}
}
+
+class CustomConnector extends SelectChannelConnector {
+ boolean mForceHttps;
+
+ public CustomConnector(boolean forceHttps) {
+ mForceHttps = forceHttps;
+ }
+
+ @Override
+ public void customize(final EndPoint endpoint, final Request request) throws IOException {
+ if (mForceHttps) {
+ request.setScheme("https");
+ super.customize(endpoint, request);
+ }
+ }
+}