Allow to force HTTPS scheme

If the standalone GitBucket instance runs behind HTTPS proxy, the
repository URL always shows HTTP scheme dispute the fact that the
connection is HTTPS. This patch is adding a command line option which
allows to force the HTTPS scheme.
This commit is contained in:
Jiri Tyr
2013-10-21 14:32:53 +01:00
parent 254509f243
commit 53269096a6
4 changed files with 37 additions and 9 deletions

View File

@@ -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 @@ public class JettyLauncher {
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 @@ public class JettyLauncher {
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 @@ public class JettyLauncher {
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);
}
}
}