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

The filename magic param isn't always removed from the request #471

Open
pkosiec opened this issue Feb 19, 2024 · 0 comments · May be fixed by #472
Open

The filename magic param isn't always removed from the request #471

pkosiec opened this issue Feb 19, 2024 · 0 comments · May be fixed by #472

Comments

@pkosiec
Copy link

pkosiec commented Feb 19, 2024

Description

The filename magic parameter sometimes isn't removed from the underlying request, which make some requests fail, e.g. when using signed URLs to GCS bucket.

Details

Based on the code, I believe all the "magic" parameters should be removed before making a request.
This is not the case in case of an URL to tar.gz directory, like this:

https://storage.googleapis.com/bucket/v1.0.0/binary_darwin_amd64.tar.gz

and configuration:

	getterCli := &getter.Client{
		Ctx:  ctx,
		Src:  url, // url with `filename` magic param
		Dst:  tmpDestPath,
		Pwd:  pwd,
		Mode: getter.ClientModeAny,
	}

I tracked the code execution, and it falls in the if which changes the mode:

mode = ClientModeFile

	if decompressor != nil {
		// ...
		mode = ClientModeFile
	}

Which is why the filename param is not removed, as the next if is skipped, which actually removes the filename param.

go-getter/client.go

Lines 230 to 249 in a2ebce9

if mode == ClientModeAny {
// Ask the getter which client mode to use
mode, err = g.ClientMode(u)
if err != nil {
return err
}
// Destination is the base name of the URL path in "any" mode when
// a file source is detected.
if mode == ClientModeFile {
filename := filepath.Base(u.Path)
// Determine if we have a custom file name
if v := q.Get("filename"); v != "" {
// Delete the query parameter if we have it.
q.Del("filename")
u.RawQuery = q.Encode()
filename = v
}

Fix incoming

I fixed it locally and will prepare a pull request soon. Hope you'll like it!

@pkosiec pkosiec linked a pull request Feb 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant