in src/handlers/web_action_handler.go [116:146]
func asyncPostWebAction(errChan chan error, url string, body []byte, headers map[string]string) {
bodyReader := strings.NewReader(string(body))
req, err := http.NewRequest("POST", ensureProtocolScheme(url), bodyReader)
if err != nil {
errChan <- err
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Length", fmt.Sprintf("%d", bodyReader.Len()))
req.ContentLength = int64(bodyReader.Len())
// Aggiungi le intestazioni opzionali
for key, value := range headers {
req.Header.Set(key, value)
}
client := &http.Client{}
httpResp, err := client.Do(req)
if err != nil {
errChan <- err
return
}
// Gestione dello stato HTTP
if httpResp.StatusCode < 200 || httpResp.StatusCode >= 300 {
errChan <- fmt.Errorf("not ok (%s)", httpResp.Status)
} else {
log.Printf("Received status code %d: %s", httpResp.StatusCode, httpResp.Status)
}
}