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

Ensure http.Response.Body is closed #363

Merged
merged 1 commit into from
Sep 7, 2022
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
6 changes: 5 additions & 1 deletion fastly/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (c *Client) ListACLs(i *ListACLsInput) ([]*ACL, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var as []*ACL
if err := decodeBodyMap(resp.Body, &as); err != nil {
Expand Down Expand Up @@ -87,6 +88,7 @@ func (c *Client) CreateACL(i *CreateACLInput) (*ACL, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var a *ACL
if err := decodeBodyMap(resp.Body, &a); err != nil {
Expand Down Expand Up @@ -126,6 +128,7 @@ func (c *Client) DeleteACL(i *DeleteACLInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand Down Expand Up @@ -168,6 +171,7 @@ func (c *Client) GetACL(i *GetACLInput) (*ACL, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var a *ACL
if err := decodeBodyMap(resp.Body, &a); err != nil {
Expand Down Expand Up @@ -211,10 +215,10 @@ func (c *Client) UpdateACL(i *UpdateACLInput) (*ACL, error) {

path := fmt.Sprintf("/service/%s/version/%d/acl/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)

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

var a *ACL
if err := decodeBodyMap(resp.Body, &a); err != nil {
Expand Down
9 changes: 7 additions & 2 deletions fastly/acl_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (c *Client) ListACLEntries(i *ListACLEntriesInput) ([]*ACLEntry, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var es []*ACLEntry
if err := decodeBodyMap(resp.Body, &es); err != nil {
Expand Down Expand Up @@ -108,7 +109,6 @@ func (c *Client) NewListACLEntriesPaginator(i *ListACLEntriesInput) PaginatorACL

// listACLEntriesWithPage return a list of entries for an ACL of a given page
func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListAclEntriesPaginator) ([]*ACLEntry, error) {

if i.ServiceID == "" {
return nil, ErrMissingServiceID
}
Expand Down Expand Up @@ -156,6 +156,7 @@ func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListAclEntrie
if err != nil {
return nil, err
}
defer resp.Body.Close()

for _, l := range link.ParseResponse(resp) {
// indicates the Link response header contained the next page instruction
Expand Down Expand Up @@ -211,6 +212,7 @@ func (c *Client) GetACLEntry(i *GetACLEntryInput) (*ACLEntry, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var e *ACLEntry
if err := decodeBodyMap(resp.Body, &e); err != nil {
Expand Down Expand Up @@ -253,6 +255,7 @@ func (c *Client) CreateACLEntry(i *CreateACLEntryInput) (*ACLEntry, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var e *ACLEntry
if err := decodeBodyMap(resp.Body, &e); err != nil {
Expand Down Expand Up @@ -289,6 +292,7 @@ func (c *Client) DeleteACLEntry(i *DeleteACLEntryInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand All @@ -300,7 +304,6 @@ func (c *Client) DeleteACLEntry(i *DeleteACLEntryInput) error {
}

return nil

}

// UpdateACLEntryInput is the input parameter to UpdateACLEntry function.
Expand Down Expand Up @@ -337,6 +340,7 @@ func (c *Client) UpdateACLEntry(i *UpdateACLEntryInput) (*ACLEntry, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var e *ACLEntry
if err := decodeBodyMap(resp.Body, &e); err != nil {
Expand Down Expand Up @@ -380,6 +384,7 @@ func (c *Client) BatchModifyACLEntries(i *BatchModifyACLEntriesInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var batchModifyResult map[string]string
if err := decodeBodyMap(resp.Body, &batchModifyResult); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions fastly/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (c *Client) ListBackends(i *ListBackendsInput) ([]*Backend, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var bs []*Backend
if err := decodeBodyMap(resp.Body, &bs); err != nil {
Expand Down Expand Up @@ -142,6 +143,7 @@ func (c *Client) CreateBackend(i *CreateBackendInput) (*Backend, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var b *Backend
if err := decodeBodyMap(resp.Body, &b); err != nil {
Expand Down Expand Up @@ -181,6 +183,7 @@ func (c *Client) GetBackend(i *GetBackendInput) (*Backend, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var b *Backend
if err := decodeBodyMap(resp.Body, &b); err != nil {
Expand Down Expand Up @@ -247,6 +250,7 @@ func (c *Client) UpdateBackend(i *UpdateBackendInput) (*Backend, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var b *Backend
if err := decodeBodyMap(resp.Body, &b); err != nil {
Expand Down Expand Up @@ -286,6 +290,7 @@ func (c *Client) DeleteBackend(i *DeleteBackendInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions fastly/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (c *Client) ListBigQueries(i *ListBigQueriesInput) ([]*BigQuery, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var bigQueries []*BigQuery
if err := decodeBodyMap(resp.Body, &bigQueries); err != nil {
Expand Down Expand Up @@ -107,6 +108,7 @@ func (c *Client) CreateBigQuery(i *CreateBigQueryInput) (*BigQuery, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var bigQuery *BigQuery
if err := decodeBodyMap(resp.Body, &bigQuery); err != nil {
Expand Down Expand Up @@ -146,6 +148,7 @@ func (c *Client) GetBigQuery(i *GetBigQueryInput) (*BigQuery, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var bigQuery *BigQuery
if err := decodeBodyMap(resp.Body, &bigQuery); err != nil {
Expand Down Expand Up @@ -197,6 +200,7 @@ func (c *Client) UpdateBigQuery(i *UpdateBigQueryInput) (*BigQuery, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var bigQuery *BigQuery
if err := decodeBodyMap(resp.Body, &bigQuery); err != nil {
Expand Down Expand Up @@ -236,6 +240,7 @@ func (c *Client) DeleteBigQuery(i *DeleteBigQueryInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand Down
1 change: 1 addition & 0 deletions fastly/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (c *Client) GetBilling(i *GetBillingInput) (*Billing, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var b *Billing
if err := decodeBodyMap(resp.Body, &b); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions fastly/blobstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (c *Client) ListBlobStorages(i *ListBlobStoragesInput) ([]*BlobStorage, err
if err != nil {
return nil, err
}
defer resp.Body.Close()

var as []*BlobStorage
if err := decodeBodyMap(resp.Body, &as); err != nil {
Expand Down Expand Up @@ -117,6 +118,7 @@ func (c *Client) CreateBlobStorage(i *CreateBlobStorageInput) (*BlobStorage, err
if err != nil {
return nil, err
}
defer resp.Body.Close()

var a *BlobStorage
if err := decodeBodyMap(resp.Body, &a); err != nil {
Expand Down Expand Up @@ -156,6 +158,7 @@ func (c *Client) GetBlobStorage(i *GetBlobStorageInput) (*BlobStorage, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var a *BlobStorage
if err := decodeBodyMap(resp.Body, &a); err != nil {
Expand Down Expand Up @@ -212,6 +215,7 @@ func (c *Client) UpdateBlobStorage(i *UpdateBlobStorageInput) (*BlobStorage, err
if err != nil {
return nil, err
}
defer resp.Body.Close()

var a *BlobStorage
if err := decodeBodyMap(resp.Body, &a); err != nil {
Expand Down Expand Up @@ -251,6 +255,7 @@ func (c *Client) DeleteBlobStorage(i *DeleteBlobStorageInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions fastly/cache_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (c *Client) ListCacheSettings(i *ListCacheSettingsInput) ([]*CacheSetting,
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cs []*CacheSetting
if err := decodeBodyMap(resp.Body, &cs); err != nil {
Expand Down Expand Up @@ -110,6 +111,7 @@ func (c *Client) CreateCacheSetting(i *CreateCacheSettingInput) (*CacheSetting,
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cs *CacheSetting
if err := decodeBodyMap(resp.Body, &cs); err != nil {
Expand Down Expand Up @@ -150,6 +152,7 @@ func (c *Client) GetCacheSetting(i *GetCacheSettingInput) (*CacheSetting, error)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cs *CacheSetting
if err := decodeBodyMap(resp.Body, &cs); err != nil {
Expand Down Expand Up @@ -195,6 +198,7 @@ func (c *Client) UpdateCacheSetting(i *UpdateCacheSettingInput) (*CacheSetting,
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cs *CacheSetting
if err := decodeBodyMap(resp.Body, &cs); err != nil {
Expand Down Expand Up @@ -234,6 +238,7 @@ func (c *Client) DeleteCacheSetting(i *DeleteCacheSettingInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions fastly/cloudfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (c *Client) ListCloudfiles(i *ListCloudfilesInput) ([]*Cloudfiles, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cloudfiles []*Cloudfiles
if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil {
Expand Down Expand Up @@ -117,6 +118,7 @@ func (c *Client) CreateCloudfiles(i *CreateCloudfilesInput) (*Cloudfiles, error)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cloudfiles *Cloudfiles
if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil {
Expand Down Expand Up @@ -156,6 +158,7 @@ func (c *Client) GetCloudfiles(i *GetCloudfilesInput) (*Cloudfiles, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cloudfiles *Cloudfiles
if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil {
Expand Down Expand Up @@ -212,6 +215,7 @@ func (c *Client) UpdateCloudfiles(i *UpdateCloudfilesInput) (*Cloudfiles, error)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cloudfiles *Cloudfiles
if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil {
Expand Down Expand Up @@ -251,6 +255,7 @@ func (c *Client) DeleteCloudfiles(i *DeleteCloudfilesInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions fastly/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (c *Client) ListConditions(i *ListConditionsInput) ([]*Condition, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cs []*Condition
if err := decodeBodyMap(resp.Body, &cs); err != nil {
Expand Down Expand Up @@ -94,6 +95,7 @@ func (c *Client) CreateCondition(i *CreateConditionInput) (*Condition, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var co *Condition
if err := decodeBodyMap(resp.Body, &co); err != nil {
Expand Down Expand Up @@ -133,6 +135,7 @@ func (c *Client) GetCondition(i *GetConditionInput) (*Condition, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var co *Condition
if err := decodeBodyMap(resp.Body, &co); err != nil {
Expand Down Expand Up @@ -177,6 +180,7 @@ func (c *Client) UpdateCondition(i *UpdateConditionInput) (*Condition, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var co *Condition
if err := decodeBodyMap(resp.Body, &co); err != nil {
Expand Down Expand Up @@ -216,6 +220,7 @@ func (c *Client) DeleteCondition(i *DeleteConditionInput) error {
if err != nil {
return err
}
defer resp.Body.Close()

var r *statusResp
if err := decodeBodyMap(resp.Body, &r); err != nil {
Expand Down
1 change: 1 addition & 0 deletions fastly/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (c *Client) EdgeCheck(i *EdgeCheckInput) ([]*EdgeCheck, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var e []*EdgeCheck
if err := decodeBodyMap(resp.Body, &e); err != nil {
Expand Down
1 change: 1 addition & 0 deletions fastly/custom_tls_activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (c *Client) UpdateTLSActivation(i *UpdateTLSActivationInput) (*TLSActivatio
if err != nil {
return nil, err
}
defer resp.Body.Close()

var ta TLSActivation
if err := jsonapi.UnmarshalPayload(resp.Body, &ta); err != nil {
Expand Down
1 change: 1 addition & 0 deletions fastly/custom_tls_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (c *Client) UpdateCustomTLSCertificate(i *UpdateCustomTLSCertificateInput)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var cc CustomTLSCertificate
if err := jsonapi.UnmarshalPayload(resp.Body, &cc); err != nil {
Expand Down
Loading