in openwhisk/stopper.go [60:106]
func SendStopRequest(ap *ActionProxy) error {
if ap.clientProxyData == nil {
Debug("Nothing to stop, runtime not set as client")
return fmt.Errorf("runtime not set as client")
}
stopRequest := stopRequest{
ProxiedActionID: ap.clientProxyData.ProxyActionID,
ActionCodeHash: ap.clientProxyData.ActionCodeHash,
}
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(stopRequest)
if err != nil {
Debug("Failed to send stop request: error encoding stop request body: %v", err)
return err
}
bodyLen := buf.Len()
body := io.NopCloser(bytes.NewBuffer(buf.Bytes()))
url := ap.clientProxyData.ProxyURL.String() + "/stop"
req, err := http.NewRequest(http.MethodPost, url, body)
if err != nil {
Debug("Failed to send stop request: error creating stop request: %v", err)
return err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Length", strconv.Itoa(bodyLen))
req.ContentLength = int64(bodyLen)
client := &http.Client{}
Debug("Sending stop request to %s", url)
resp, err := client.Do(req)
if err != nil {
Debug("Failed to send stop request: %v", err)
return err
}
respBody, _ := io.ReadAll(resp.Body)
defer resp.Body.Close()
Debug("Stop request response: %v", string(respBody))
return nil
}