curl和wget在查询Docker Hub速率时行为不同。

huangapple go评论61阅读模式
英文:

curl and wget behavior differently when querying Docker Hub rate

问题

I am wondering what makes the curl and wget behavior differently when query docker hub download rate.

Dockre docs said we can use the following curl command to get the docker hub remain rate.

docker_hub_rate() {
  local IMAGE=${1:-ratelimitpreview/test}
  local RESPONSE=$(wget -qO- "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${IMAGE}:pull")
  local TOKEN=$(echo ${RESPONSE} | sed 's/.*"token":"\([^"]*\).*//')
  local HEADER="Authorization: Bearer ${TOKEN}"
  local URL="https://registry-1.docker.io/v2/${IMAGE}/manifests/latest"
  RESPONSE=$(curl --head -H "${HEADER}" "${URL}" 2>&1)
  echo ${RESPONSE}
}

I have an environment where there is no curl, only wget is available. So I change the command to

docker_hub_rate() {
  local IMAGE=${1:-ratelimitpreview/test}
  local RESPONSE=$(wget -qO- "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${IMAGE}:pull")
  local TOKEN=$(echo ${RESPONSE} | sed 's/.*"token":"\([^"]*\).*//')
  local HEADER="Authorization: Bearer ${TOKEN}"
  local URL="https://registry-1.docker.io/v2/${IMAGE}/manifests/latest"
  RESPONSE=$(wget -qS --header="${HEADER}" -O /dev/null "${URL}" 2>&1)
  echo ${RESPONSE}
}

I am still able to get the rate.

However I found that wget command consumed one docker hub rate, while curl did not consume any docker hub rate.

I am wondering what makes the curl and wget behavior differently?

Thanks,

both curl and wget consume no docker hub download rate.

英文:

I am wondering what makes the curl and wget behavior differently when query docker hub download rate.

Dockre docs said we can use the following curl command to get the docker hub remain rate.

docker_hub_rate() {
  local IMAGE=${1:-ratelimitpreview/test}
  local RESPONSE=$(wget -qO- "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${IMAGE}:pull")
  local TOKEN=$(echo ${RESPONSE} | sed 's/.*"token":"\([^"]*\).*//')
  local HEADER="Authorization: Bearer ${TOKEN}"
  local URL="https://registry-1.docker.io/v2/${IMAGE}/manifests/latest"
  RESPONSE=$(curl --head -H "${HEADER}" "${URL}" 2>&1)
  echo ${RESPONSE}
}

I have an environment where there is no curl, only wget is available. So I change the command to

docker_hub_rate() {
  local IMAGE=${1:-ratelimitpreview/test}
  local RESPONSE=$(wget -qO- "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${IMAGE}:pull")
  local TOKEN=$(echo ${RESPONSE} | sed 's/.*"token":"\([^"]*\).*//')
  local HEADER="Authorization: Bearer ${TOKEN}"
  local URL="https://registry-1.docker.io/v2/${IMAGE}/manifests/latest"
  RESPONSE=$(wget -qS --header="${HEADER}" -O /dev/null "${URL}" 2>&1)
  echo ${RESPONSE}
}

I am still able to get the rate.

However I found that wget command consumed one docker hub rate, while curl did not consume any docker hub rate.

I am wondering what makes the curl and wget behavior differently?

Thanks,

both curl and wget consume no docker hub download rate.

答案1

得分: 1

curl --headwget -S 是不同的

curl:

-I, --head

(HTTP FTP FILE) 仅获取头部!HTTP服务器支持HEAD命令,该命令用于仅获取文档的标题。在FTP或FILE文件上使用时,curl仅显示文件大小和最后修改时间。

wget:

-S 会显示头部,但它执行的是GET请求,而不是HEAD。换句话说,它会获取整个URL。

使用Wget时,添加--spider意味着您要发送一个HEAD请求(而不是GET或POST)。

来源

英文:

curl --head and wget -S are different

curl

> -I, --head
>
> (HTTP FTP FILE) Fetch the headers only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on an FTP or FILE file, curl displays the file size and last modification time only.

wget:
> -S will show headers, but it executes a GET, not a HEAD. In other words, it will fetch the entire URL.

> With Wget, adding --spider implies that you want to send a HEAD request (as opposed to GET or POST).

source

huangapple
  • 本文由 发表于 2023年6月16日 08:15:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486228.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定