refactor(confighttp): HTML page handlers into generic getPage function (#4645)

This commit is contained in:
David Lane
2026-03-08 18:36:22 -04:00
committed by GitHub
parent 3fbbe88b79
commit f04f6a2bde
13 changed files with 1250 additions and 275 deletions
+11 -6
View File
@@ -1,15 +1,21 @@
function generateExamples(endpoint, method, body = null) {
let curlBodyString = '';
let curlHeaderString = '';
let psBodyString = '';
let psContentTypeString = '';
let psBodyParams = '';
if (body) {
const curlJsonString = JSON.stringify(body).replace(/"/g, '\\"');
curlBodyString = ` -d "${curlJsonString}"`;
curlHeaderString = ' -H "Content-Type: application/json"';
psBodyString = `-Body (ConvertTo-Json ${JSON.stringify(body)})`;
psContentTypeString = '-ContentType \'application/json\'';
psBodyParams = ' `\n ' + psBodyString + ' `\n ' + psContentTypeString;
}
return {
cURL: `curl -u user:pass -H "Content-Type: application/json" -X ${method.trim()} -k https://localhost:47990${endpoint.trim()}${curlBodyString}`,
cURL: `curl -u user:pass${curlHeaderString} -X ${method.trim()} -k https://localhost:47990${endpoint.trim()}${curlBodyString}`,
Python: `import json
import requests
from requests.auth import HTTPBasicAuth
@@ -22,19 +28,18 @@ requests.${method.trim().toLowerCase()}(
JavaScript: `fetch('https://localhost:47990${endpoint.trim()}', {
method: '${method.trim()}',
headers: {
'Authorization': 'Basic ' + btoa('user:pass'),
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('user:pass'),${body ? `\n 'Content-Type': 'application/json',` : ''}
}${body ? `,\n body: JSON.stringify(${JSON.stringify(body)}),` : ''}
})
.then(response => response.json())
.then(data => console.log(data));`,
PowerShell: `Invoke-RestMethod \`
-SkipCertificateCheck \`
-ContentType 'application/json' \`
-Uri 'https://localhost:47990${endpoint.trim()}' \`
-Method ${method.trim()} \`
-Headers @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('user:pass'))}
${psBodyString}`
-Headers @{
Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('user:pass'))
}${psBodyParams}`
};
}