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

Purge with Soft=true bug #266

Closed
yassine-y opened this issue Mar 25, 2021 · 2 comments
Closed

Purge with Soft=true bug #266

yassine-y opened this issue Mar 25, 2021 · 2 comments
Labels

Comments

@yassine-y
Copy link

Purge with soft=true is broken


// Purge instantly purges an individual URL.
func (c *Client) Purge(i *PurgeInput) (*Purge, error) {
	if i.URL == "" {
		return nil, ErrMissingURL
	}

	ro := new(RequestOptions)
	ro.Parallel = true
	if i.Soft {
		ro.Headers["Fastly-Soft-Purge"] = "1"
	}

	resp, err := c.Post("purge/"+i.URL, ro)
	if err != nil {
		return nil, err
	}

	var r *Purge
	if err := decodeBodyMap(resp.Body, &r); err != nil {
		return nil, err
	}
	return r, nil
}

this line access a non initialized map maybe! ro.Headers["Fastly-Soft-Purge"] = "1"

@Integralist
Copy link
Collaborator

Thanks for raising this issue @you-yas55

I'm able to replicate the bug you've described using a test service:

p, err := client.Purge(&fastly.PurgeInput{
	URL:  "http://testing-gofastly-purge.integralist-test.com.global.prod.fastly.net/anything/foo",
	Soft: true,
})

Which triggers a panic:

panic: assignment to entry in nil map

@Integralist
Copy link
Collaborator

The call to new(RequestOptions) only sets a zero value for the .Headers map (which for a map type is nil) hence trying to assign a value to nil results in a panic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants