瀏覽代碼

Set host header for link validator (#2409)

pull/2653/head
Dmytro Khmelenko 2 年之前
committed by GitHub
父節點
當前提交
3979c871cd
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. +8
    -1
      build/validate_links.py

+ 8
- 1
build/validate_links.py 查看文件

@@ -51,9 +51,16 @@ def validate_links(links):
for link in links:
h = httplib2.Http(disable_ssl_certificate_validation=True, timeout=25)
try:
# fetching host name, removing leading www
host = link.split('//', 1)[1].split('/', 1)[0]
if host[:3] == 'www':
host = host[4:]
resp = h.request(link, headers={
# Faking user agent as some hosting services block not-whitelisted UA
'user-agent': 'Mozilla/5.0'
'user-agent': 'Mozilla/5.0',
# setting host because Cloudflare returns 403 asking for captcha if host is missing
'host': host
})
code = int(resp[0]['status'])
# Checking status code errors


Loading…
取消
儲存