Enhance ProxyManager and ProxyValidator to display detailed response information, including status codes, response data, and headers. Implement response data truncation for better readability. Update validation logic to capture and return response details in case of errors.
This commit is contained in:
parent
6c3b3928f9
commit
a4127509af
@ -333,6 +333,42 @@ class ProxyManager {
|
||||
document.getElementById('validationStatus').textContent = '验证完成';
|
||||
|
||||
// 显示结果
|
||||
let responseResultHtml = '';
|
||||
|
||||
if (result.data.responseStatus !== null && result.data.responseStatus !== undefined) {
|
||||
responseResultHtml = `
|
||||
<hr>
|
||||
<h6>响应结果:</h6>
|
||||
<p><strong>状态码:</strong> <span class="badge ${result.data.responseStatus >= 200 && result.data.responseStatus < 300 ? 'bg-success' : 'bg-warning'}">${result.data.responseStatus}</span></p>
|
||||
`;
|
||||
|
||||
if (result.data.responseData) {
|
||||
// 限制显示长度,避免内容过长
|
||||
let displayData = result.data.responseData;
|
||||
const maxLength = 300;
|
||||
if (displayData.length > maxLength) {
|
||||
displayData = displayData.substring(0, maxLength) + '... (内容已截断,完整内容请查看日志)';
|
||||
}
|
||||
|
||||
responseResultHtml += `
|
||||
<p><strong>响应内容:</strong></p>
|
||||
<pre class="bg-light p-2 border rounded" style="max-height: 200px; overflow-y: auto; font-size: 12px; white-space: pre-wrap; word-wrap: break-word;">${this.escapeHtml(displayData)}</pre>
|
||||
`;
|
||||
}
|
||||
|
||||
if (result.data.testUrl) {
|
||||
responseResultHtml += `
|
||||
<p class="text-muted small"><strong>测试URL:</strong> ${result.data.testUrl}</p>
|
||||
`;
|
||||
}
|
||||
} else if (result.data.error) {
|
||||
responseResultHtml = `
|
||||
<hr>
|
||||
<h6>响应结果:</h6>
|
||||
<p class="text-danger"><strong>错误:</strong> ${result.data.error}</p>
|
||||
`;
|
||||
}
|
||||
|
||||
document.getElementById('validationResults').innerHTML = `
|
||||
<div class="alert ${result.data.isValid ? 'alert-success' : 'alert-danger'}">
|
||||
<h6>验证结果: ${result.data.isValid ? '成功' : '失败'}</h6>
|
||||
@ -340,6 +376,7 @@ class ProxyManager {
|
||||
<p><strong>响应时间:</strong> ${result.data.responseTime}ms</p>
|
||||
${result.data.error ? `<p><strong>错误信息:</strong> ${result.data.error}</p>` : ''}
|
||||
</div>
|
||||
${responseResultHtml}
|
||||
`;
|
||||
|
||||
// 延迟刷新列表
|
||||
@ -581,6 +618,13 @@ class ProxyManager {
|
||||
return icons[type] || 'info-circle-fill';
|
||||
}
|
||||
|
||||
escapeHtml(text) {
|
||||
if (!text) return '';
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
convertToCSV(data) {
|
||||
if (!data || data.length === 0) return '';
|
||||
|
||||
|
||||
@ -94,13 +94,32 @@ class ProxyValidator {
|
||||
console.log(`✓ 代理 ${ip}:${port} 第 ${attemptNumber} 次尝试验证成功,响应时间: ${responseTime}ms`);
|
||||
}
|
||||
|
||||
// 提取响应信息用于显示
|
||||
let responseData = '';
|
||||
let responseStatus = response.status;
|
||||
try {
|
||||
// 只取响应数据的前500个字符,避免数据过大
|
||||
const dataStr = typeof response.data === 'string'
|
||||
? response.data
|
||||
: JSON.stringify(response.data);
|
||||
responseData = dataStr.substring(0, 500);
|
||||
if (dataStr.length > 500) {
|
||||
responseData += '... (已截断)';
|
||||
}
|
||||
} catch (e) {
|
||||
responseData = '无法解析响应内容';
|
||||
}
|
||||
|
||||
const result = {
|
||||
ip: ip,
|
||||
port: parseInt(port),
|
||||
isValid: true,
|
||||
responseTime: responseTime,
|
||||
error: null,
|
||||
testUrl: testUrl
|
||||
testUrl: testUrl,
|
||||
responseStatus: responseStatus,
|
||||
responseData: responseData,
|
||||
responseHeaders: response.headers || {}
|
||||
};
|
||||
|
||||
// 更新数据库中的验证结果(如果需要)
|
||||
@ -124,13 +143,33 @@ class ProxyValidator {
|
||||
}
|
||||
|
||||
lastError = new Error('响应内容验证失败');
|
||||
// 提取响应信息
|
||||
let responseData = '';
|
||||
let responseStatus = response ? response.status : null;
|
||||
try {
|
||||
if (response && response.data) {
|
||||
const dataStr = typeof response.data === 'string'
|
||||
? response.data
|
||||
: JSON.stringify(response.data);
|
||||
responseData = dataStr.substring(0, 500);
|
||||
if (dataStr.length > 500) {
|
||||
responseData += '... (已截断)';
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
responseData = '无法解析响应内容';
|
||||
}
|
||||
|
||||
lastResult = {
|
||||
ip: ip,
|
||||
port: parseInt(port),
|
||||
isValid: false,
|
||||
responseTime: responseTime,
|
||||
error: '响应内容验证失败',
|
||||
testUrl: testUrl
|
||||
testUrl: testUrl,
|
||||
responseStatus: responseStatus,
|
||||
responseData: responseData,
|
||||
responseHeaders: response ? (response.headers || {}) : {}
|
||||
};
|
||||
|
||||
// 如果还有重试机会,继续尝试
|
||||
@ -147,7 +186,10 @@ class ProxyValidator {
|
||||
isValid: false,
|
||||
responseTime: responseTime,
|
||||
error: error.message,
|
||||
testUrl: testUrl
|
||||
testUrl: testUrl,
|
||||
responseStatus: null,
|
||||
responseData: null,
|
||||
responseHeaders: {}
|
||||
};
|
||||
|
||||
if (logResult) {
|
||||
@ -184,7 +226,10 @@ class ProxyValidator {
|
||||
isValid: false,
|
||||
responseTime: Date.now() - startTime,
|
||||
error: lastError ? lastError.message : '所有验证尝试都失败',
|
||||
testUrl: testUrl
|
||||
testUrl: testUrl,
|
||||
responseStatus: null,
|
||||
responseData: null,
|
||||
responseHeaders: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user