diff --git a/build.xml b/build.xml
index 187359e..d39324e 100644
--- a/build.xml
+++ b/build.xml
@@ -46,7 +46,7 @@
+ includes="JettyLauncher.class,SslConnector.class"/>
diff --git a/contrib/redhat/gitbucket.conf b/contrib/redhat/gitbucket.conf
index fb14ebe..26e4201 100644
--- a/contrib/redhat/gitbucket.conf
+++ b/contrib/redhat/gitbucket.conf
@@ -1,6 +1,9 @@
# 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..390318c 100644
--- a/contrib/redhat/gitbucket.init
+++ b/contrib/redhat/gitbucket.init
@@ -35,6 +35,9 @@
if [ $GITBUCKET_PREFIX ]; then
START_OPTS="${START_OPTS} --prefix ${GITBUCKET_PREFIX}"
fi
+ if [ $GITBUCKET_HTTPS ]; then
+ START_OPTS="${START_OPTS} --https=true"
+ fi
# Run the Java process
GITBUCKET_HOME="${GITBUCKET_HOME}" java $GITBUCKET_JVM_OPTS -jar $GITBUCKET_WAR_FILE $START_OPTS >>$LOG_FILE 2>&1 &
diff --git a/src/main/java/JettyLauncher.java b/src/main/java/JettyLauncher.java
index 356da21..c56398b 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 httpsScheme = 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"))) {
+ httpsScheme = true;
}
}
}
@@ -28,8 +34,8 @@
Server server = new Server();
- SelectChannelConnector connector = new SelectChannelConnector();
- if(host != null){
+ SslConnector connector = new SslConnector(httpsScheme);
+ if(host != null) {
connector.setHost(host);
}
connector.setMaxIdleTime(1000 * 60 * 60);
@@ -51,3 +57,19 @@
server.join();
}
}
+
+class SslConnector extends SelectChannelConnector {
+ boolean myHttpsScheme;
+
+ public SslConnector(boolean httpsScheme) {
+ myHttpsScheme = httpsScheme;
+ }
+
+ @Override
+ public void customize(final EndPoint endpoint, final Request request) throws IOException {
+ if (myHttpsScheme) {
+ request.setScheme("https");
+ super.customize(endpoint, request);
+ }
+ }
+}