mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
修复ui 添加gost静默http服务
This commit is contained in:
@@ -136,3 +136,7 @@ else
|
||||
echo "❌ gost服务启动失败,请执行以下命令查看日志:"
|
||||
echo "journalctl -u gost -f"
|
||||
fi
|
||||
|
||||
# 删除安装脚本自身
|
||||
echo "🧹 清理安装脚本..."
|
||||
rm -f "$0" 2>/dev/null && echo "✨ 安装脚本已自动清理" || echo "⚠️ 安装脚本清理失败,请手动删除"
|
||||
|
||||
@@ -82,3 +82,8 @@ echo "JWT_SECRET=$JWT_SECRET"
|
||||
echo "SERVER_HOST=$SERVER_HOST_PORT"
|
||||
echo "FRONTEND_PORT=$FRONTEND_PORT"
|
||||
echo "BACKEND_PORT=$BACKEND_PORT"
|
||||
|
||||
# 清理安装文件
|
||||
echo "🧹 清理安装文件..."
|
||||
rm -f docker-compose.yml gost.sql 2>/dev/null && echo "✨ 下载文件已清理" || echo "⚠️ 下载文件清理失败"
|
||||
rm -f "$0" 2>/dev/null && echo "✨ 安装脚本已自动清理" || echo "⚠️ 安装脚本清理失败,请手动删除"
|
||||
|
||||
@@ -102,34 +102,19 @@ public class HttpUtils implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义错误处理器,不抛出异常但记录错误信息
|
||||
* 自定义错误处理器,不抛出异常,允许获取所有状态码的响应
|
||||
*/
|
||||
private static class NoOpResponseErrorHandler implements ResponseErrorHandler {
|
||||
@Override
|
||||
public boolean hasError(ClientHttpResponse response) throws IOException {
|
||||
HttpStatus statusCode = response.getStatusCode();
|
||||
return statusCode.series() == HttpStatus.Series.CLIENT_ERROR ||
|
||||
statusCode.series() == HttpStatus.Series.SERVER_ERROR;
|
||||
// 返回 false,让 RestTemplate 不认为任何状态码是错误
|
||||
// 这样就可以正常获取 4xx 和 5xx 的响应体
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
HttpStatus statusCode = response.getStatusCode();
|
||||
String statusText = response.getStatusText();
|
||||
String responseBody = "";
|
||||
|
||||
try {
|
||||
// 使用Spring的StreamUtils来读取响应体
|
||||
responseBody = new String(
|
||||
StreamUtils.copyToByteArray(response.getBody()),
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
} catch (Exception e) {
|
||||
responseBody = "无法读取响应体: " + e.getMessage();
|
||||
}
|
||||
|
||||
logger.error("HTTP请求错误 - 状态码: {} {}, 响应体: {}",
|
||||
statusCode.value(), statusText, responseBody);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,11 +47,13 @@ public class RestTemplateConfig {
|
||||
SSLConnectionSocketFactory connectionSocketFactory = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
|
||||
HttpClientBuilder httpClientBuilder = HttpClients.custom();
|
||||
|
||||
|
||||
httpClientBuilder.setSSLSocketFactory(connectionSocketFactory);
|
||||
CloseableHttpClient httpClient = httpClientBuilder.build();
|
||||
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
|
||||
factory.setHttpClient(httpClient);
|
||||
// 添加超时配置
|
||||
factory.setConnectTimeout(TIMEOUT_MILLISECONDS);
|
||||
factory.setReadTimeout(TIMEOUT_MILLISECONDS);
|
||||
return factory;
|
||||
}
|
||||
|
||||
@@ -67,6 +69,9 @@ public class RestTemplateConfig {
|
||||
CloseableHttpClient httpClient = httpClientBuilder.build();
|
||||
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
|
||||
factory.setHttpClient(httpClient);
|
||||
// 添加超时配置
|
||||
factory.setConnectTimeout(TIMEOUT_MILLISECONDS);
|
||||
factory.setReadTimeout(TIMEOUT_MILLISECONDS);
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user