无法下载远程 https svg 文件,但嵌入 <img> 是好的

Fail to download a remote https svg file but embed inside <img> is good

我有一个httpslink,嵌入<img>,一切都很好。如 https://jsfiddle.net/Lbhhtt6n/. However, if you try to download link directly such as directly open it with browser with link https://version.gitlab.com/check.svg?gitlab_info=eyJ2ZXJzaW9uIjoiOC4xNi4wLXByZSJ9 ,则返回 404 错误。

由于这个问题,我无法通过 httparty

检查头部
response = HTTParty.head('https://version.gitlab.com/check.svg?gitlab_info=eyJ2ZXJzaW9uIjoiOC4xNi4wLXByZSJ9')
puts response.success? # always return false

它背后的魔力是什么?任何人都可以启发我吗?谢谢。

如果你通知 HTTP Refer header. Otherwise it responds with 404. See details at https://about.gitlab.com/handbook/sales-process/version_check,Gitlab 只会给你图像。

当您尝试通过浏览器地址栏或任何其他工具获取资源而未明确设置 header 时,您将收到 404。

它在加载为页面资源(例如 img 标签)时有效,因为浏览器会为您发送 header。

亲身体验一下它的实际效果:

$ curl -v https://version.gitlab.com/check.svg?gitlab_info=eyJ2ZXJzaW9uIjoiOC4xNi4wLXByZSJ9

$ curl -v https://version.gitlab.com/check.svg?gitlab_info=eyJ2ZXJzaW9uIjoiOC4xNi4wLXByZSJ9 -e whosebug.com


查看 Chrome 开发者工具显示的差异:

作为页面资源:

来自地址栏: