@@ -8060,6 +8060,7 @@ async function handleGatewayTestSubmit(e) {
80608060 const baseUrl = formData.get("url");
80618061 const method = formData.get("method");
80628062 const path = formData.get("path");
8063+ const contentType = formData.get("content_type") || "application/json";
80638064
80648065 // Validate URL
80658066 const urlValidation = validateUrl(baseUrl);
@@ -8099,12 +8100,28 @@ async function handleGatewayTestSubmit(e) {
80998100 throw new Error(bodyValidation.error);
81008101 }
81018102
8103+ // Process body based on content type
8104+ let processedBody = bodyValidation.value;
8105+ if (
8106+ contentType === "application/x-www-form-urlencoded" &&
8107+ bodyValidation.value &&
8108+ typeof bodyValidation.value === "object"
8109+ ) {
8110+ // Convert JSON object to URL-encoded string
8111+ const params = new URLSearchParams();
8112+ Object.entries(bodyValidation.value).forEach(([key, value]) => {
8113+ params.append(key, String(value));
8114+ });
8115+ processedBody = params.toString();
8116+ }
8117+
81028118 const payload = {
81038119 base_url: urlValidation.value,
81048120 method,
81058121 path,
81068122 headers: headersValidation.value,
8107- body: bodyValidation.value,
8123+ body: processedBody,
8124+ content_type: contentType,
81088125 };
81098126
81108127 // Make the request with timeout
@@ -17556,3 +17573,21 @@ style.textContent = `
1755617573 }
1755717574`;
1755817575document.head.appendChild(style);
17576+
17577+ // Function to update body label based on content type selection
17578+ function updateBodyLabel() {
17579+ const bodyLabel = document.getElementById("gateway-test-body-label");
17580+ const contentType = document.getElementById(
17581+ "gateway-test-content-type",
17582+ )?.value;
17583+
17584+ if (bodyLabel) {
17585+ bodyLabel.innerHTML =
17586+ contentType === "application/x-www-form-urlencoded"
17587+ ? 'Body (JSON)<br><small class="text-gray-500">Auto-converts to form data</small>'
17588+ : "Body (JSON)";
17589+ }
17590+ }
17591+
17592+ // Make it available globally for HTML onclick handlers
17593+ window.updateBodyLabel = updateBodyLabel;
0 commit comments