From e93433892b9a42fa1ef759f72fceb4a4b2ad3b6d Mon Sep 17 00:00:00 2001 From: Chang Su Date: Fri, 2 Jan 2026 16:02:42 -0800 Subject: [PATCH] refactor(steps): consolidate duplicate strip_protocol function (#16318) --- .../src/core/steps/worker/local/detect_connection.rs | 9 +-------- .../src/core/steps/worker/local/discover_metadata.rs | 9 +-------- sgl-model-gateway/src/core/steps/worker/local/mod.rs | 8 ++++++++ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/sgl-model-gateway/src/core/steps/worker/local/detect_connection.rs b/sgl-model-gateway/src/core/steps/worker/local/detect_connection.rs index 697fb59d0..bdefd759a 100644 --- a/sgl-model-gateway/src/core/steps/worker/local/detect_connection.rs +++ b/sgl-model-gateway/src/core/steps/worker/local/detect_connection.rs @@ -6,6 +6,7 @@ use async_trait::async_trait; use reqwest::Client; use tracing::debug; +use super::strip_protocol; use crate::{ app_context::AppContext, core::ConnectionMode, @@ -14,14 +15,6 @@ use crate::{ workflow::{StepExecutor, StepId, StepResult, WorkflowContext, WorkflowError, WorkflowResult}, }; -/// Strip protocol prefix from URL. -fn strip_protocol(url: &str) -> String { - url.trim_start_matches("http://") - .trim_start_matches("https://") - .trim_start_matches("grpc://") - .to_string() -} - /// Try HTTP health check. async fn try_http_health_check( url: &str, diff --git a/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs b/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs index ef7a6d150..c330d295b 100644 --- a/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs +++ b/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use tracing::{debug, warn}; +use super::strip_protocol; use crate::{ core::ConnectionMode, protocols::worker_spec::WorkerConfigRequest, @@ -50,14 +51,6 @@ pub struct ModelInfo { pub architectures: Option>, } -/// Strip protocol prefix from URL. -fn strip_protocol(url: &str) -> String { - url.trim_start_matches("http://") - .trim_start_matches("https://") - .trim_start_matches("grpc://") - .to_string() -} - /// Fallback function to GET JSON from old endpoint (with "get_" prefix) for backward compatibility. async fn get_json_fallback( base_url: &str, diff --git a/sgl-model-gateway/src/core/steps/worker/local/mod.rs b/sgl-model-gateway/src/core/steps/worker/local/mod.rs index 6c12d599f..7ecdefdd4 100644 --- a/sgl-model-gateway/src/core/steps/worker/local/mod.rs +++ b/sgl-model-gateway/src/core/steps/worker/local/mod.rs @@ -13,6 +13,14 @@ mod update_worker_properties; use std::{sync::Arc, time::Duration}; +/// Strip protocol prefix (http://, https://, grpc://) from URL. +pub(crate) fn strip_protocol(url: &str) -> String { + url.trim_start_matches("http://") + .trim_start_matches("https://") + .trim_start_matches("grpc://") + .to_string() +} + pub use create_worker::CreateLocalWorkerStep; pub use detect_connection::DetectConnectionModeStep; pub use discover_dp::{get_dp_info, DiscoverDPInfoStep, DpInfo};