INNER CODE UNIT · Go
newSafeClient
orneryd/NornicDB · cmd/eval/main.go:46
func newSafeClient(timeout time.Duration) *safeClient {
return &safeClient{client: &http.Client{Timeout: timeout}}
}
// Get performs a GET request after validating the URL is localhost-only.
func (s *safeClient) Get(rawURL string) (*http.Response, error) {
if err := validateURL(rawURL); err != nil {
return nil, fmt.Errorf("SSRF protection: %w", err)
}
return s.client.Get(rawURL)
}
// Post performs a POST request after validating the URL is localhost-only.
func (s *safeClient) Post(rawURL, contentType string, body io.Reader) (*http.Response, error) {
if err := validateURL(rawURL); err != nil {
return nil, fmt.Errorf("SSRF protection: %w", err)
}
return s.client.Post(rawURL, contentType, body)