fix: proxy-call location and values
This commit is contained in:
@@ -269,24 +269,18 @@ func (c *SporeClient) buildProxyRequest(method, targetURL string, params map[str
|
||||
var contentType string
|
||||
|
||||
if method != "GET" && params != nil {
|
||||
// Check if we have JSON parameters
|
||||
hasJSONParams := false
|
||||
jsonParams := make(map[string]interface{})
|
||||
// Use form-encoded data for all body parameters (matching index-standalone.js behavior)
|
||||
form := make(map[string][]string)
|
||||
query := make(map[string][]string)
|
||||
|
||||
for name, value := range params {
|
||||
location := "body"
|
||||
paramType := "string"
|
||||
|
||||
// Check if value is a parameter object with location and type info
|
||||
// Check if value is a parameter object with location info
|
||||
if paramObj, ok := value.(map[string]interface{}); ok {
|
||||
if loc, exists := paramObj["location"].(string); exists {
|
||||
location = loc
|
||||
}
|
||||
if ptype, exists := paramObj["type"].(string); exists {
|
||||
paramType = ptype
|
||||
}
|
||||
// Extract the actual value
|
||||
if val, exists := paramObj["value"]; exists {
|
||||
value = val
|
||||
@@ -307,17 +301,9 @@ func (c *SporeClient) buildProxyRequest(method, targetURL string, params map[str
|
||||
targetURL = strings.ReplaceAll(targetURL, placeholder, fmt.Sprintf("%v", value))
|
||||
}
|
||||
default:
|
||||
// Special handling for certain parameters that expect form-encoded data
|
||||
// even when marked as "json" type
|
||||
if paramType == "json" && name == "labels" {
|
||||
// The labels parameter expects form-encoded data, not JSON
|
||||
form[name] = append(form[name], fmt.Sprintf("%v", value))
|
||||
} else if paramType == "json" {
|
||||
hasJSONParams = true
|
||||
jsonParams[name] = value
|
||||
} else {
|
||||
form[name] = append(form[name], fmt.Sprintf("%v", value))
|
||||
}
|
||||
// Use form-encoded data for all body parameters (matching index-standalone.js behavior)
|
||||
// This is simpler and more reliable than trying to detect JSON automatically
|
||||
form[name] = append(form[name], fmt.Sprintf("%v", value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,17 +324,8 @@ func (c *SporeClient) buildProxyRequest(method, targetURL string, params map[str
|
||||
targetURL = urlObj.String()
|
||||
}
|
||||
|
||||
// Create request body
|
||||
if hasJSONParams {
|
||||
// Send JSON body
|
||||
jsonData, err := json.Marshal(jsonParams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal JSON params: %w", err)
|
||||
}
|
||||
body = strings.NewReader(string(jsonData))
|
||||
contentType = "application/json"
|
||||
} else if len(form) > 0 {
|
||||
// Send form-encoded body
|
||||
// Create request body - always use form-encoded data for consistency
|
||||
if len(form) > 0 {
|
||||
data := url.Values{}
|
||||
for key, values := range form {
|
||||
for _, value := range values {
|
||||
|
||||
Reference in New Issue
Block a user