mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
use configured server port in cgis for mod_proxy
This commit is contained in:
@@ -39,6 +39,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.io.RegexResourceProcessor;
|
||||
import sonia.scm.io.ResourceProcessor;
|
||||
import sonia.scm.repository.BzrConfig;
|
||||
@@ -116,15 +117,19 @@ public class BzrCGIServlet extends AbstractCGIServlet
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param securityContextProvider
|
||||
* @param repositoryManager
|
||||
* @param handler
|
||||
*/
|
||||
@Inject
|
||||
public BzrCGIServlet(Provider<WebSecurityContext> securityContextProvider,
|
||||
public BzrCGIServlet(ScmConfiguration configuration,
|
||||
Provider<WebSecurityContext> securityContextProvider,
|
||||
RepositoryManager repositoryManager,
|
||||
BzrRepositoryHandler handler)
|
||||
{
|
||||
super(configuration);
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.handler = handler;
|
||||
|
||||
@@ -38,6 +38,7 @@ package sonia.scm.web;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -88,13 +89,17 @@ public class HgCGIServlet extends AbstractCGIServlet
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param repositoryManager
|
||||
* @param handler
|
||||
*/
|
||||
@Inject
|
||||
public HgCGIServlet(RepositoryManager repositoryManager,
|
||||
public HgCGIServlet(ScmConfiguration configuration,
|
||||
RepositoryManager repositoryManager,
|
||||
HgRepositoryHandler handler)
|
||||
{
|
||||
super(configuration);
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@
|
||||
|
||||
package sonia.scm.util;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -75,6 +79,37 @@ public class HttpUtil
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getServerPort(ScmConfiguration configuration,
|
||||
HttpServletRequest request)
|
||||
{
|
||||
int port = 0;
|
||||
|
||||
if (configuration.isEnableSSL())
|
||||
{
|
||||
port = configuration.getSslPort();
|
||||
}
|
||||
else
|
||||
{
|
||||
port = configuration.getPort();
|
||||
}
|
||||
|
||||
if (port <= 0)
|
||||
{
|
||||
port = request.getLocalPort();
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
|
||||
package sonia.scm.web.cgi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
@@ -55,6 +60,19 @@ public abstract class AbstractCGIServlet extends HttpServlet
|
||||
/** Field description */
|
||||
private static final long serialVersionUID = -8638099037069714140L;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
*/
|
||||
public AbstractCGIServlet(ScmConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -157,7 +175,7 @@ public abstract class AbstractCGIServlet extends HttpServlet
|
||||
{
|
||||
cgiRunner.exec(createRequestEnvironment(req, baseEnvironment),
|
||||
getCmdPrefix(), getCommand(req), req.getPathInfo(), req,
|
||||
resp);
|
||||
resp, HttpUtil.getServerPort(configuration, req));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -191,4 +209,7 @@ public abstract class AbstractCGIServlet extends HttpServlet
|
||||
|
||||
/** Field description */
|
||||
private CGIRunner cgiRunner;
|
||||
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
}
|
||||
|
||||
@@ -103,10 +103,10 @@ public class CGIRunner
|
||||
* @throws IOException
|
||||
*/
|
||||
public void exec(EnvList environment, File command, String pathInfo,
|
||||
HttpServletRequest req, HttpServletResponse res)
|
||||
HttpServletRequest req, HttpServletResponse res, int serverPort)
|
||||
throws IOException
|
||||
{
|
||||
exec(environment, defaultCmdPrefix, command, pathInfo, req, res);
|
||||
exec(environment, defaultCmdPrefix, command, pathInfo, req, res, serverPort);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +125,7 @@ public class CGIRunner
|
||||
*/
|
||||
public void exec(EnvList environment, String cmdPrefix, File command,
|
||||
String pathInfo, HttpServletRequest req,
|
||||
HttpServletResponse res)
|
||||
HttpServletResponse res, int serverPort)
|
||||
throws IOException
|
||||
{
|
||||
String path = command.getAbsolutePath();
|
||||
@@ -169,7 +169,7 @@ public class CGIRunner
|
||||
environment.set("SCRIPT_NAME", scriptName);
|
||||
environment.set("SCRIPT_FILENAME", scriptPath);
|
||||
environment.set("SERVER_NAME", req.getServerName());
|
||||
environment.set("SERVER_PORT", Integer.toString(req.getServerPort()));
|
||||
environment.set("SERVER_PORT", Integer.toString(serverPort));
|
||||
environment.set("SERVER_PROTOCOL", req.getProtocol());
|
||||
environment.set("SERVER_SOFTWARE", context.getServerInfo());
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ import java.util.Collection;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -233,7 +234,7 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
StringBuilder url = new StringBuilder(request.getScheme());
|
||||
|
||||
url.append("://").append(configuration.getServername());
|
||||
url.append(":").append(getPort(request));
|
||||
url.append(":").append(HttpUtil.getServerPort(configuration, request));
|
||||
|
||||
String ctxPath = request.getContextPath();
|
||||
|
||||
@@ -271,34 +272,7 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private int getPort(HttpServletRequest request)
|
||||
{
|
||||
int port = 0;
|
||||
|
||||
if (configuration.isEnableSSL())
|
||||
{
|
||||
port = configuration.getSslPort();
|
||||
}
|
||||
else
|
||||
{
|
||||
port = configuration.getPort();
|
||||
}
|
||||
|
||||
if (port <= 0)
|
||||
{
|
||||
port = request.getLocalPort();
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
|
||||
Reference in New Issue
Block a user