英文:
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 --head
和 wget -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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论