use std::process::Command;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🔬 Protocol Test - Testing different approaches");
let host = "sg-vdb-99wnoegp.sql.tencentcdb.com";
let port = "8100";
let username = std::env::var("VECTORDB_USERNAME").unwrap_or_else(|_| "root".to_string());
let api_key = std::env::var("VECTORDB_API_KEY").unwrap_or_else(|_| "test".to_string());
println!("🔧 Testing different HTTP approaches:");
println!("\n1️⃣ Testing HTTPS:");
let https_url = format!("https://{}:{}/database/list", host, port);
let https_test = Command::new("curl")
.arg("-k") .arg("-v")
.arg("-X")
.arg("GET")
.arg("-H")
.arg("Content-Type: application/json")
.arg("-H")
.arg(format!("Authorization: Bearer account={}&api_key={}", username, api_key))
.arg(&https_url)
.output();
match https_test {
Ok(result) => {
println!("HTTPS test result:");
println!("Status: {}", result.status);
if result.status.success() {
println!("✅ HTTPS successful!");
println!("Response: {}", String::from_utf8_lossy(&result.stdout));
} else {
println!("❌ HTTPS failed");
println!("Stderr: {}", String::from_utf8_lossy(&result.stderr));
}
}
Err(e) => {
println!("❌ Failed to execute HTTPS test: {}", e);
}
}
println!("\n2️⃣ Testing HTTP/2:");
let http2_url = format!("http://{}:{}/database/list", host, port);
let http2_test = Command::new("curl")
.arg("--http2")
.arg("-v")
.arg("-X")
.arg("GET")
.arg("-H")
.arg("Content-Type: application/json")
.arg("-H")
.arg(format!("Authorization: Bearer account={}&api_key={}", username, api_key))
.arg(&http2_url)
.output();
match http2_test {
Ok(result) => {
println!("HTTP/2 test result:");
if result.status.success() {
println!("✅ HTTP/2 successful!");
println!("Response: {}", String::from_utf8_lossy(&result.stdout));
} else {
println!("❌ HTTP/2 failed");
println!("Stderr: {}", String::from_utf8_lossy(&result.stderr));
}
}
Err(e) => {
println!("❌ Failed to execute HTTP/2 test: {}", e);
}
}
println!("\n3️⃣ Testing raw HTTP request:");
let raw_http_request = format!(
"GET /database/list HTTP/1.1\r\n\
Host: {}:{}\r\n\
Authorization: Bearer account={}&api_key={}\r\n\
Content-Type: application/json\r\n\
Connection: close\r\n\
\r\n",
host, port, username, api_key
);
println!("Raw HTTP request:");
println!("{}", raw_http_request);
let nc_test = Command::new("sh")
.arg("-c")
.arg(format!("echo -e '{}' | nc {} {}", raw_http_request.replace("\r\n", "\\r\\n"), host, port))
.output();
match nc_test {
Ok(result) => {
println!("Raw HTTP test result:");
println!("Status: {}", result.status);
println!("Response: {}", String::from_utf8_lossy(&result.stdout));
if !result.stderr.is_empty() {
println!("Stderr: {}", String::from_utf8_lossy(&result.stderr));
}
}
Err(e) => {
println!("❌ Failed to execute raw HTTP test: {}", e);
}
}
println!("\n4️⃣ Testing different endpoints:");
let endpoints = vec!["/", "/health", "/status", "/api/health"];
for endpoint in endpoints {
let test_url = format!("http://{}:{}{}", host, port, endpoint);
println!("Testing endpoint: {}", endpoint);
let endpoint_test = Command::new("curl")
.arg("-v")
.arg("--connect-timeout")
.arg("5")
.arg("--max-time")
.arg("10")
.arg(&test_url)
.output();
match endpoint_test {
Ok(result) => {
if result.status.success() {
println!(" ✅ {} successful!", endpoint);
println!(" Response: {}", String::from_utf8_lossy(&result.stdout));
} else {
println!(" ❌ {} failed", endpoint);
}
}
Err(e) => {
println!(" ❌ Failed to test {}: {}", endpoint, e);
}
}
}
println!("\n📋 Recommendations:");
println!("1. The server accepts TCP connections but doesn't respond to HTTP");
println!("2. This could indicate:");
println!(" - Server is not running HTTP service on port 8100");
println!(" - Server requires a specific protocol or handshake");
println!(" - Server is behind a load balancer that's not configured properly");
println!(" - Server requires HTTPS instead of HTTP");
println!(" - Server has strict request validation");
println!("3. Contact your VectorDB administrator to verify:");
println!(" - Correct protocol (HTTP vs HTTPS)");
println!(" - Correct port number");
println!(" - Required headers or authentication format");
println!(" - Server status and logs");
Ok(())
}