Skip to content

The Unified and Autonomous Development Platform

fix: Binding to a specific IP address breaks pushing, because localhost is used with curl (OD-2682)

Robin Shen8a04ac95f099
diff --git a/server-core/src/main/java/io/onedev/server/git/hook/HookUtils.java b/server-core/src/main/java/io/onedev/server/git/hook/HookUtils.java
index 8dfa5c1096..9993ff91dc 100644
--- a/server-core/src/main/java/io/onedev/server/git/hook/HookUtils.java
+++ b/server-core/src/main/java/io/onedev/server/git/hook/HookUtils.java
@@ -44,12 +44,7 @@ public class HookUtils {
envs.put("ONEDEV_HOOK_TOKEN", HOOK_TOKEN);
envs.put("ONEDEV_USER_ID", principal);
envs.put("ONEDEV_REPOSITORY_ID", projectId.toString());
-
- envs.put("GITPLEX_CURL", curl);
- envs.put("GITPLEX_URL", hookUrl);
- envs.put("GITPLEX_USER_ID", principal);
- envs.put("GITPLEX_REPOSITORY_ID", projectId.toString());
-
+
return envs;
}
diff --git a/server-product/src/main/java/io/onedev/server/product/ProductConfigurator.java b/server-product/src/main/java/io/onedev/server/product/ProductConfigurator.java
index 20a10cb9fd..9f16a4ae89 100644
--- a/server-product/src/main/java/io/onedev/server/product/ProductConfigurator.java
+++ b/server-product/src/main/java/io/onedev/server/product/ProductConfigurator.java
@@ -23,14 +23,26 @@ public class ProductConfigurator implements ServerConfigurator {
@Override
public void configure(Server server) {
- ServerConnector connector = new ServerConnector(server);
- connector.setHost(serverConfig.getHttpHost());
- connector.setPort(serverConfig.getHttpPort());
HttpConfiguration configuration = new HttpConfiguration();
configuration.setRequestHeaderSize(REQUEST_HEADER_SIZE);
configuration.setSendServerVersion(false);
+
+ ServerConnector connector = new ServerConnector(server);
+ connector.setHost(serverConfig.getHttpHost());
+ connector.setPort(serverConfig.getHttpPort());
connector.addConnectionFactory(new HttpConnectionFactory(configuration));
server.addConnector(connector);
+
+ // If http_host is a specific IP (not 0.0.0.0), also bind to localhost as curl needs to access localhost
+ // for git operations
+ String httpHost = serverConfig.getHttpHost();
+ if (!"0.0.0.0".equals(httpHost) && !"127.0.0.1".equals(httpHost) && !"localhost".equals(httpHost)) {
+ ServerConnector localhostConnector = new ServerConnector(server);
+ localhostConnector.setHost("127.0.0.1");
+ localhostConnector.setPort(serverConfig.getHttpPort());
+ localhostConnector.addConnectionFactory(new HttpConnectionFactory(configuration));
+ server.addConnector(localhostConnector);
+ }
}
}
diff --git a/server-product/system/conf/server.properties b/server-product/system/conf/server.properties
index c73ffa10bb..e95253ab01 100644
--- a/server-product/system/conf/server.properties
+++ b/server-product/system/conf/server.properties
@@ -1,4 +1,6 @@
-# Specify bind address for http service, use 0.0.0.0 to listen on all interfaces
+# Specify bind address for http service, use 0.0.0.0 to listen on all interfaces.
+# Note that 127.0.0.1 will always be bound as OneDev needs to access localhost for
+# some internal operations.
http_host=0.0.0.0
# Specify port for http service