使用 curl 下载 golang tarball 产生奇怪的结果
Using curl to download golang tarball produces strange result
我试图在 Ubuntu 21.10 上安装 golang。这需要下载 golang tarball 并将其解压缩到文件系统上的特定位置。首先我尝试了:
curl -O https://go.dev/dl/go1.17.7.linux-amd64.tar.gz
它只是创建了一个包含以下文本的文件:
<a href="https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz">Found</a>.
带有详细标志的相同命令输出:
$ curl -v https://go.dev/dl/go1.17.7.linux-amd64.tar.gz
* Trying 216.239.32.21:443...
* Connected to go.dev (216.239.32.21) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=go.dev
* start date: Feb 11 11:23:46 2022 GMT
* expire date: May 12 11:23:45 2022 GMT
* subjectAltName: host "go.dev" matched cert's "go.dev"
* issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1D4
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55726a1bb5e0)
> GET /dl/go1.17.7.linux-amd64.tar.gz HTTP/2
> Host: go.dev
> user-agent: curl/7.74.0
> accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
< HTTP/2 302
< content-type: text/html; charset=utf-8
< content-security-policy: connect-src 'self' www.google-analytics.com stats.g.doubleclick.net ; default-src 'self' ; font-src 'self' fonts.googleapis.com fonts.gstatic.com data: ; frame-ancestors 'self' ; frame-src 'self' www.google.com feedback.googleusercontent.com www.googletagmanager.com scone-pa.clients6.google.com www.youtube.com player.vimeo.com ; img-src 'self' www.google.com www.google-analytics.com ssl.gstatic.com www.gstatic.com gstatic.com data: * ; object-src 'none' ; script-src 'self' 'sha256-n6OdwTrm52KqKm6aHYgD0TFUdMgww4a0GQlIAVrMzck=' 'sha256-4ryYrf7Y5daLOBv0CpYtyBIcJPZkRD2eBPdfqsN3r1M=' 'sha256-sVKX08+SqOmnWhiySYk3xC7RDUgKyAkmbXV2GWts4fo=' www.google.com apis.google.com www.gstatic.com gstatic.com support.google.com www.googletagmanager.com www.google-analytics.com ssl.google-analytics.com tagmanager.google.com ; style-src 'self' 'unsafe-inline' fonts.googleapis.com feedback.googleusercontent.com www.gstatic.com gstatic.com tagmanager.google.com ;
< location: https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-cloud-trace-context: 7611c1786413210c614a80a1da377a17
< date: Thu, 24 Feb 2022 05:02:13 GMT
< server: Google Frontend
< content-length: 75
<
<a href="https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz">Found</a>.
* Connection #0 to host go.dev left intact
tarball 下载与 wget 命令配合使用效果很好。我尝试阅读更多有关两者之间差异的信息,并认为 curl 应该有效。在下载 linux 源 tarball 的档案时,我以前从未遇到过使用 curl 的问题。我真的不确定问题出在 curl 还是 golang 服务器上。任何解释都会有所帮助。
问题
https://go.dev/dl/go1.17.7.linux-amd64.tar.gz is performing a redirect to https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz
我们可以在您上面提供的输出中看到这一点
location: https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz
wget
默认遵循重定向(最多 20 个)- 请参阅 man page
然而,curl
默认情况下不遵循重定向(但默认最大值为 50)。
解决方案
-L
将使 curl 跟随重定向
curl -OL https://go.dev/dl/go1.17.7.linux-amd64.tar.gz
Use -L, --location to follow redirects and use -f, --fail so server data is not written to the file on server error.
我试图在 Ubuntu 21.10 上安装 golang。这需要下载 golang tarball 并将其解压缩到文件系统上的特定位置。首先我尝试了:
curl -O https://go.dev/dl/go1.17.7.linux-amd64.tar.gz
它只是创建了一个包含以下文本的文件:
<a href="https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz">Found</a>.
带有详细标志的相同命令输出:
$ curl -v https://go.dev/dl/go1.17.7.linux-amd64.tar.gz
* Trying 216.239.32.21:443...
* Connected to go.dev (216.239.32.21) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=go.dev
* start date: Feb 11 11:23:46 2022 GMT
* expire date: May 12 11:23:45 2022 GMT
* subjectAltName: host "go.dev" matched cert's "go.dev"
* issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1D4
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55726a1bb5e0)
> GET /dl/go1.17.7.linux-amd64.tar.gz HTTP/2
> Host: go.dev
> user-agent: curl/7.74.0
> accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
< HTTP/2 302
< content-type: text/html; charset=utf-8
< content-security-policy: connect-src 'self' www.google-analytics.com stats.g.doubleclick.net ; default-src 'self' ; font-src 'self' fonts.googleapis.com fonts.gstatic.com data: ; frame-ancestors 'self' ; frame-src 'self' www.google.com feedback.googleusercontent.com www.googletagmanager.com scone-pa.clients6.google.com www.youtube.com player.vimeo.com ; img-src 'self' www.google.com www.google-analytics.com ssl.gstatic.com www.gstatic.com gstatic.com data: * ; object-src 'none' ; script-src 'self' 'sha256-n6OdwTrm52KqKm6aHYgD0TFUdMgww4a0GQlIAVrMzck=' 'sha256-4ryYrf7Y5daLOBv0CpYtyBIcJPZkRD2eBPdfqsN3r1M=' 'sha256-sVKX08+SqOmnWhiySYk3xC7RDUgKyAkmbXV2GWts4fo=' www.google.com apis.google.com www.gstatic.com gstatic.com support.google.com www.googletagmanager.com www.google-analytics.com ssl.google-analytics.com tagmanager.google.com ; style-src 'self' 'unsafe-inline' fonts.googleapis.com feedback.googleusercontent.com www.gstatic.com gstatic.com tagmanager.google.com ;
< location: https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz
< strict-transport-security: max-age=31536000; includeSubDomains; preload
< x-cloud-trace-context: 7611c1786413210c614a80a1da377a17
< date: Thu, 24 Feb 2022 05:02:13 GMT
< server: Google Frontend
< content-length: 75
<
<a href="https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz">Found</a>.
* Connection #0 to host go.dev left intact
tarball 下载与 wget 命令配合使用效果很好。我尝试阅读更多有关两者之间差异的信息,并认为 curl 应该有效。在下载 linux 源 tarball 的档案时,我以前从未遇到过使用 curl 的问题。我真的不确定问题出在 curl 还是 golang 服务器上。任何解释都会有所帮助。
问题
https://go.dev/dl/go1.17.7.linux-amd64.tar.gz is performing a redirect to https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz
我们可以在您上面提供的输出中看到这一点
location: https://dl.google.com/go/go1.17.7.linux-amd64.tar.gz
wget
默认遵循重定向(最多 20 个)- 请参阅 man page
然而,curl
默认情况下不遵循重定向(但默认最大值为 50)。
解决方案
-L
将使 curl 跟随重定向
curl -OL https://go.dev/dl/go1.17.7.linux-amd64.tar.gz
Use -L, --location to follow redirects and use -f, --fail so server data is not written to the file on server error.