Skip to content

Commit

Permalink
fix(request): URL encode names properly
Browse files Browse the repository at this point in the history
The name of a Fastly resource is used as reference in the URL to GET, PUT, or DELETE a specific
element. The Fastly API accepts all kind of special characters including forward slashes which need
to be URL encoded. Otherwise, the element can't be found in the DB and the Fastly API returns a 404
Not Found error.

fix #65
  • Loading branch information
philippschulte committed May 15, 2019
1 parent f249287 commit 8b3e2d6
Show file tree
Hide file tree
Showing 199 changed files with 2,324 additions and 1,839 deletions.
7 changes: 4 additions & 3 deletions fastly/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
)

Expand Down Expand Up @@ -118,7 +119,7 @@ func (c *Client) DeleteACL(i *DeleteACLInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/acl/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/acl/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down Expand Up @@ -159,7 +160,7 @@ func (c *Client) GetACL(i *GetACLInput) (*ACL, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/acl/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/acl/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -204,7 +205,7 @@ func (c *Client) UpdateACL(i *UpdateACLInput) (*ACL, error) {
return nil, ErrMissingNewName
}

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

if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions fastly/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
)

Expand Down Expand Up @@ -163,7 +164,7 @@ func (c *Client) GetBackend(i *GetBackendInput) (*Backend, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/backend/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/backend/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -227,7 +228,7 @@ func (c *Client) UpdateBackend(i *UpdateBackendInput) (*Backend, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/backend/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/backend/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -265,7 +266,7 @@ func (c *Client) DeleteBackend(i *DeleteBackendInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/backend/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/backend/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions fastly/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
)

// BigQuery represents a BigQuery logging response from the Fastly API.
Expand Down Expand Up @@ -266,7 +267,7 @@ func (c *Client) UpdateBigQuery(i *UpdateBigQueryInput) (*BigQuery, error) {
params["placement"] = i.Placement
}

path := fmt.Sprintf("/service/%s/version/%d/logging/bigquery/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/logging/bigquery/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, &RequestOptions{
Params: params,
})
Expand Down Expand Up @@ -308,7 +309,7 @@ func (c *Client) DeleteBigQuery(i *DeleteBigQueryInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/logging/bigquery/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/logging/bigquery/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions fastly/blobstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
"time"
)
Expand Down Expand Up @@ -144,7 +145,7 @@ func (c *Client) GetBlobStorage(i *GetBlobStorageInput) (*BlobStorage, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/logging/azureblob/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/logging/azureblob/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -197,7 +198,7 @@ func (c *Client) UpdateBlobStorage(i *UpdateBlobStorageInput) (*BlobStorage, err
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/logging/azureblob/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/logging/azureblob/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -235,7 +236,7 @@ func (c *Client) DeleteBlobStorage(i *DeleteBlobStorageInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/logging/azureblob/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/logging/azureblob/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions fastly/cache_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
)

Expand Down Expand Up @@ -138,7 +139,7 @@ func (c *Client) GetCacheSetting(i *GetCacheSettingInput) (*CacheSetting, error)
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/cache_settings/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/cache_settings/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -182,7 +183,7 @@ func (c *Client) UpdateCacheSetting(i *UpdateCacheSettingInput) (*CacheSetting,
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/cache_settings/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/cache_settings/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -220,7 +221,7 @@ func (c *Client) DeleteCacheSetting(i *DeleteCacheSettingInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/cache_settings/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/cache_settings/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions fastly/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
)

Expand Down Expand Up @@ -134,7 +135,7 @@ func (c *Client) GetDictionary(i *GetDictionaryInput) (*Dictionary, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -175,7 +176,7 @@ func (c *Client) UpdateDictionary(i *UpdateDictionaryInput) (*Dictionary, error)
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -213,7 +214,7 @@ func (c *Client) DeleteDictionary(i *DeleteDictionaryInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions fastly/dictionary_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
)

Expand Down Expand Up @@ -146,7 +147,7 @@ func (c *Client) GetDictionaryItem(i *GetDictionaryItemInput) (*DictionaryItem,
return nil, ErrMissingItemKey
}

path := fmt.Sprintf("/service/%s/dictionary/%s/item/%s", i.Service, i.Dictionary, i.ItemKey)
path := fmt.Sprintf("/service/%s/dictionary/%s/item/%s", i.Service, i.Dictionary, url.PathEscape(i.ItemKey))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -186,7 +187,7 @@ func (c *Client) UpdateDictionaryItem(i *UpdateDictionaryItemInput) (*Dictionary
return nil, ErrMissingItemKey
}

path := fmt.Sprintf("/service/%s/dictionary/%s/item/%s", i.Service, i.Dictionary, i.ItemKey)
path := fmt.Sprintf("/service/%s/dictionary/%s/item/%s", i.Service, i.Dictionary, url.PathEscape(i.ItemKey))
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -224,7 +225,7 @@ func (c *Client) DeleteDictionaryItem(i *DeleteDictionaryItemInput) error {
return ErrMissingItemKey
}

path := fmt.Sprintf("/service/%s/dictionary/%s/item/%s", i.Service, i.Dictionary, i.ItemKey)
path := fmt.Sprintf("/service/%s/dictionary/%s/item/%s", i.Service, i.Dictionary, url.PathEscape(i.ItemKey))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions fastly/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
)

Expand Down Expand Up @@ -147,7 +148,7 @@ func (c *Client) GetDirector(i *GetDirectorInput) (*Director, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/director/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/director/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -193,7 +194,7 @@ func (c *Client) UpdateDirector(i *UpdateDirectorInput) (*Director, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/director/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/director/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -231,7 +232,7 @@ func (c *Client) DeleteDirector(i *DeleteDirectorInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/director/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/director/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions fastly/director_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"time"
)

Expand Down Expand Up @@ -52,7 +53,7 @@ func (c *Client) CreateDirectorBackend(i *CreateDirectorBackendInput) (*Director
}

path := fmt.Sprintf("/service/%s/version/%d/director/%s/backend/%s",
i.Service, i.Version, i.Director, i.Backend)
i.Service, i.Version, url.PathEscape(i.Director), url.PathEscape(i.Backend))
resp, err := c.PostForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -98,7 +99,7 @@ func (c *Client) GetDirectorBackend(i *GetDirectorBackendInput) (*DirectorBacken
}

path := fmt.Sprintf("/service/%s/version/%d/director/%s/backend/%s",
i.Service, i.Version, i.Director, i.Backend)
i.Service, i.Version, url.PathEscape(i.Director), url.PathEscape(i.Backend))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -144,7 +145,7 @@ func (c *Client) DeleteDirectorBackend(i *DeleteDirectorBackendInput) error {
}

path := fmt.Sprintf("/service/%s/version/%d/director/%s/backend/%s",
i.Service, i.Version, i.Director, i.Backend)
i.Service, i.Version, url.PathEscape(i.Director), url.PathEscape(i.Backend))
resp, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions fastly/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"fmt"
"net/url"
"sort"
)

Expand Down Expand Up @@ -118,7 +119,7 @@ func (c *Client) GetDomain(i *GetDomainInput) (*Domain, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/domain/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/domain/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -163,7 +164,7 @@ func (c *Client) UpdateDomain(i *UpdateDomainInput) (*Domain, error) {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/domain/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/domain/%s", i.Service, i.Version, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -201,7 +202,7 @@ func (c *Client) DeleteDomain(i *DeleteDomainInput) error {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/domain/%s", i.Service, i.Version, i.Name)
path := fmt.Sprintf("/service/%s/version/%d/domain/%s", i.Service, i.Version, url.PathEscape(i.Name))
_, err := c.Delete(path, nil)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 8b3e2d6

Please sign in to comment.