Skip to content

Commit ea47960

Browse files
authored
Merge pull request #12 from doganarif/feature/request-comparison-tool
Feature: Add Request Comparison Tool for Side-by-Side Analysis
2 parents e01a896 + b6ca884 commit ea47960

File tree

3 files changed

+871
-1
lines changed

3 files changed

+871
-1
lines changed

internal/dashboard/handler.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4444
case "/api/clear":
4545
h.handleClearRequests(w, r)
4646
return
47+
case "/api/compare":
48+
h.handleCompareRequests(w, r)
49+
return
4750
case "/":
4851
h.handleDashboard(w, r)
4952
return
@@ -156,6 +159,37 @@ func (h *Handler) handleSSE(w http.ResponseWriter, r *http.Request) {
156159
}
157160
}
158161

162+
// handleCompareRequests serves the JSON API for comparing specific requests
163+
func (h *Handler) handleCompareRequests(w http.ResponseWriter, r *http.Request) {
164+
w.Header().Set("Content-Type", "application/json")
165+
166+
// Get request IDs from query parameters
167+
ids := r.URL.Query()["id"]
168+
if len(ids) < 2 {
169+
http.Error(w, "At least two request IDs are required", http.StatusBadRequest)
170+
return
171+
}
172+
173+
// Get all requests
174+
allRequests := h.store.GetAll()
175+
176+
// Filter requests by IDs
177+
compareRequests := []interface{}{}
178+
for _, req := range allRequests {
179+
for _, id := range ids {
180+
if req.ID == id {
181+
compareRequests = append(compareRequests, req)
182+
break
183+
}
184+
}
185+
}
186+
187+
// Return the filtered requests
188+
encoder := json.NewEncoder(w)
189+
encoder.SetEscapeHTML(false)
190+
encoder.Encode(compareRequests)
191+
}
192+
159193
// isSensitiveEnvVar returns true if the environment variable key is considered sensitive
160194
func isSensitiveEnvVar(key string) bool {
161195
sensitiveKeys := []string{

0 commit comments

Comments
 (0)