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

x/website/internal/dl: make https://golang.org/dl/{file} URLs more useful #38713

Closed
dmitshur opened this issue Apr 27, 2020 · 5 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Apr 27, 2020

Go binary downloads have been available at the URL https://golang.org/dl/{file} since at least 2015 (see CL 14842). That URL serves a 302 Found redirect to another URL which serves the actual bytes. The exact target of redirection is an implementation detail that has changed over the years (e.g., most recently in CL 76971).

The https://golang.org/dl/{file} URL is short, memorable, has golang.org in it, and has been around for long enough that it's temping to perceive to be more future-proof than any URL it happens to point to (similar to how https://golang.org/issue/123 is more future-proof than a direct link to an issue tracker, https://code.google.com/p/go/issues/detail?id=123).

However, as far as I can tell so far, it doesn't seem to be used on golang.org or documented anywhere:

  1. The links on the https://golang.org/dl/ HTML page point directly the redirect target of https://golang.org/dl/{file}, which is https://dl.google.com/go/{file} since 2017.
  2. The API endpoint at https://golang.org/dl/?mode=json has filenames only.
  3. Package golang.org/x/website/internal/dl documentation doesn't mention it.

The only documentation seems to be the source code. That makes it difficult to recommend as a future-proof URL (to use in scripts, etc.) despite the favorable properties above.

Also see #22648 (it was about the redirect target URLs).

/cc @andybons @mvdan @adg @broady @bradfitz

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 27, 2020
@dmitshur dmitshur added this to the Unreleased milestone Apr 27, 2020
@dmitshur
Copy link
Contributor Author

I think we can fix this issue by changing the links on the https://golang.org/dl/ HTML page to use https://golang.org/dl/{file}. That will help establish them as canonical URLs, and make it less troublesome if we ever need to change where the actual bytes are served from. If someone wants to be able to do curl without -L flag, they can continue to use the redirect target.

Am I missing any context? Thoughts?

@bradfitz
Copy link
Contributor

IIRC the original point of that handler was just to make go get golang.org/dl/go1.n.m work (as in https://twitter.com/golang/status/1248018480479096833 etc).

But once we had the go-get metadata, we needed to do something the URLs about non-cmd/go clients. That was never the goal, though.

@dmitshur
Copy link
Contributor Author

dmitshur commented Apr 27, 2020

In 2015, getHandler was serving the list of downloads (the https://golang.org/dl/ page), the files themselves (via redirect to a GCS URL at the time), and 404 for everything else. This is from CL 14842:

func getHandler(w http.ResponseWriter, r *http.Request) {
	name := strings.TrimPrefix(r.URL.Path, "/dl/")
	if name == "" {
		listHandler(w, r)
		return
	}
	if !fileRe.MatchString(name) {
		http.NotFound(w, r)
		return
	}
	http.Redirect(w, r, gcsBaseURL+name, http.StatusFound)
}

The ?go-get=1 code path for golang.org/dl/go1.n.m commands was added in 2018 via CL 123679.

@dmitshur
Copy link
Contributor Author

There haven't been concerns or objections raised regarding the solution I suggested in #38713 (comment). I plan to proceed with it soon. In the unlikely case we learn of something that goes poorly as a result, this will be easy to undo.

@dmitshur dmitshur self-assigned this Jun 12, 2020
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 12, 2020
@gopherbot
Copy link

Change https://golang.org/cl/238517 mentions this issue: internal/dl: use /dl/{file} URLs on /dl/ HTML page

@golang golang locked and limited conversation to collaborators Jun 30, 2021
passionSeven added a commit to passionSeven/website that referenced this issue Oct 18, 2022
The /dl/{file} URLs have been supported for many years but not well
documented. Start using them on the /dl/ HTML page and document them,
so that it is clear that they can be reliably used in scripts or so.

This causes clients to have to make an extra HTTP request (which gets
redirected to the target location serving the file bytes), but compared
to the total work to download a Go file, this is negligible. Clients
that really want to skip the redirect can do so, but the trade-off is
that they need to update the URL if the CDN used for Go file downloads
happens to change. The /dl/{file} links are not expected to change for
Go 1.

Fixes golang/go#38713.

Change-Id: I9df7d5b761baa6fa657c5dd2063c97b9b457367c
Reviewed-on: https://go-review.googlesource.com/c/website/+/238517
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants