HTTPGet performs a GET request using Extism's built-in HTTP functionality. Only hostnames configured in the policy engine's AllowedHosts are accessible. Returns error if the hostname is not allowed or the request fails.
(url string)
| 26 | // Only hostnames configured in the policy engine's AllowedHosts are accessible. |
| 27 | // Returns error if the hostname is not allowed or the request fails. |
| 28 | func HTTPGet(url string) ([]byte, error) { |
| 29 | req := pdk.NewHTTPRequest(pdk.MethodGet, url) |
| 30 | resp := req.Send() |
| 31 | |
| 32 | if resp.Status() != 200 { |
| 33 | return nil, fmt.Errorf("HTTP request failed with status %d", resp.Status()) |
| 34 | } |
| 35 | |
| 36 | return resp.Body(), nil |
| 37 | } |
| 38 | |
| 39 | // HTTPGetJSON performs a GET request and unmarshals the JSON response. |
| 40 | // Only hostnames configured in the policy engine's AllowedHosts are accessible. |
no test coverage detected