Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Ensure that HTTP response body objects are always closed. #592

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fastly/automation_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ type CreateAutomationTokenInput struct {
//
// Requires sudo capability for the token being used.
func (c *Client) CreateAutomationToken(i *CreateAutomationTokenInput) (*AutomationToken, error) {
_, err := c.PostForm("/sudo", i, nil)
ignored, err := c.PostForm("/sudo", i, nil)
if err != nil {
return nil, err
}
defer ignored.Body.Close()

resp, err := c.PostJSON("/automation-tokens", i, nil)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions fastly/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@ func (c *Client) DeleteDomain(i *DeleteDomainInput) error {

path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "domain", i.Name)

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}

// ValidateDomainInput is used as input to the ValidateDomain function.
Expand Down
16 changes: 12 additions & 4 deletions fastly/kv_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,12 @@ func (c *Client) InsertKVStoreKey(i *InsertKVStoreKeyInput) error {
}
defer resp.Body.Close()

_, err = checkResp(resp, err)
return err
ignored, err := checkResp(resp, err)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}

// DeleteKVStoreKeyInput is the input to the DeleteKVStoreKey function.
Expand Down Expand Up @@ -534,6 +538,10 @@ func (c *Client) BatchModifyKVStoreKey(i *BatchModifyKVStoreKeyInput) error {
}
defer resp.Body.Close()

_, err = checkResp(resp, err)
return err
ignored, err := checkResp(resp, err)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/managed_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (c *Client) DeleteManagedLogging(i *DeleteManagedLoggingInput) error {
return ErrNotImplemented
}

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/product_enablement.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (c *Client) DisableProduct(i *ProductEnablementInput) error {

path := ToSafeURL("enabled-products", i.ProductID.String(), "services", i.ServiceID)

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
9 changes: 6 additions & 3 deletions fastly/service_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ func (c *Client) DeleteServiceAuthorization(i *DeleteServiceAuthorizationInput)

path := ToSafeURL("service-authorizations", i.ID)

_, err := c.Delete(path, nil)

return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/tls_custom_activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func (c *Client) DeleteTLSActivation(i *DeleteTLSActivationInput) error {

path := ToSafeURL("tls", "activations", i.ID)

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/tls_custom_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ func (c *Client) DeleteCustomTLSCertificate(i *DeleteCustomTLSCertificateInput)

path := ToSafeURL("tls", "certificates", i.ID)

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/tls_mutual_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ func (c *Client) DeleteTLSMutualAuthentication(i *DeleteTLSMutualAuthenticationI

path := ToSafeURL("tls", "mutual_authentications", i.ID)

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/tls_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func (c *Client) DeleteBulkCertificate(i *DeleteBulkCertificateInput) error {

path := ToSafeURL("tls", "bulk", "certificates", i.ID)

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/tls_private_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func (c *Client) DeletePrivateKey(i *DeletePrivateKeyInput) error {

path := ToSafeURL("tls", "private_keys", i.ID)

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/tls_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ func (c *Client) DeleteTLSSubscription(i *DeleteTLSSubscriptionInput) error {

path := ToSafeURL("tls", "subscriptions", i.ID)

_, err := c.Delete(path, &ro)
return err
ignored, err := c.Delete(path, &ro)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
11 changes: 8 additions & 3 deletions fastly/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ type CreateTokenInput struct {

// CreateToken creates a new resource.
func (c *Client) CreateToken(i *CreateTokenInput) (*Token, error) {
_, err := c.PostForm("/sudo", i, nil)
ignored, err := c.PostForm("/sudo", i, nil)
if err != nil {
return nil, err
}
defer ignored.Body.Close()

resp, err := c.PostForm("/tokens", i, nil)
if err != nil {
Expand Down Expand Up @@ -194,6 +195,10 @@ func (c *Client) BatchDeleteTokens(i *BatchDeleteTokensInput) error {
if len(i.Tokens) == 0 {
return ErrMissingTokensValue
}
_, err := c.DeleteJSONAPIBulk("/tokens", i.Tokens, nil)
return err
ignored, err := c.DeleteJSONAPIBulk("/tokens", i.Tokens, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/waf.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,12 @@ func (c *Client) DeleteWAF(i *DeleteWAFInput) error {

path := ToSafeURL("waf", "firewalls", i.ID)

_, err := c.DeleteJSONAPI(path, i, nil)
return err
ignored, err := c.DeleteJSONAPI(path, i, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}

// infoResponse is used to pull the links and meta from the result.
Expand Down
8 changes: 6 additions & 2 deletions fastly/waf_active_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func (c *Client) DeleteWAFActiveRules(i *DeleteWAFActiveRulesInput) error {

path := ToSafeURL("waf", "firewalls", i.WAFID, "versions", strconv.Itoa(i.WAFVersionNumber), "active-rules")

_, err := c.DeleteJSONAPIBulk(path, i.Rules, nil)
return err
ignored, err := c.DeleteJSONAPIBulk(path, i.Rules, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/waf_rule_exclusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ func (c *Client) DeleteWAFRuleExclusion(i *DeleteWAFRuleExclusionInput) error {

path := ToSafeURL("waf", "firewalls", i.WAFID, "versions", strconv.Itoa(i.WAFVersionNumber), "exclusions", strconv.Itoa(i.Number))

_, err := c.Delete(path, nil)
return err
ignored, err := c.Delete(path, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}
8 changes: 6 additions & 2 deletions fastly/waf_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,12 @@ func (c *Client) DeployWAFVersion(i *DeployWAFVersionInput) error {

path := ToSafeURL("waf", "firewalls", i.WAFID, "versions", strconv.Itoa(i.WAFVersionNumber), "activate")

_, err := c.PutJSONAPI(path, &DeployWAFVersionInput{}, nil)
return err
ignored, err := c.PutJSONAPI(path, &DeployWAFVersionInput{}, nil)
if err != nil {
return err
}
defer ignored.Body.Close()
return nil
}

// CreateEmptyWAFVersionInput creates a new resource.
Expand Down