惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
P
Privacy & Cybersecurity Law Blog
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
S
Security @ Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
A
Arctic Wolf
Webroot Blog
Webroot Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Security Latest
Security Latest
H
Heimdal Security Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
T
Tor Project blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
A
About on SuperTechFans
M
MIT News - Artificial intelligence
V
V2EX
V
Visual Studio Blog
Recorded Future
Recorded Future
博客园 - 叶小钗
F
Fortinet All Blogs
L
Lohrmann on Cybersecurity
The GitHub Blog
The GitHub Blog
博客园 - Franky
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)
I
InfoQ
SecWiki News
SecWiki News
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
J
Java Code Geeks
B
Blog RSS Feed
AWS News Blog
AWS News Blog
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
H
Help Net Security

jobcher on 打工人日志

2023-12-21 打工人日报 2023-12-20 打工人日报 2023-12-19 打工人日报 2023-12-18 打工人日报 2023-12-17 打工人日报 2023-12-16 打工人日报 2023-12-15 打工人日报 2023-12-14 打工人日报 2023-12-13 打工人日报 2023-12-12 打工人日报 2023-12-11 打工人日报 2023-12-10 打工人日报 2023-12-09 打工人日报 2023-12-08 打工人日报 2023-12-07 打工人日报 2023-12-06 打工人日报 2023-12-05 打工人日报 2023-12-04 打工人日报 2023-12-03 打工人日报 2023-12-02 打工人日报 2023-12-01 打工人日报 2023-11-30 打工人日报 2023-11-29 打工人日报 2023-11-28 打工人日报 2023-11-27 打工人日报 2023-11-26 打工人日报 2023-11-25 打工人日报 2023-11-24 打工人日报 2023-11-23 打工人日报 2023-11-22 打工人日报 2023-11-21 打工人日报 2023-11-20 打工人日报 2023-11-19 打工人日报 2023-11-17 打工人日报 2023-11-16 打工人日报 2023-11-15 打工人日报 2023-11-14 打工人日报 2023-11-13 打工人日报 2023-11-12 打工人日报 2023-11-11 打工人日报 2023-11-10 打工人日报 2023-11-09 打工人日报 2023-11-08 打工人日报 2023-11-07 打工人日报 2023-11-06 打工人日报 2023-11-05 打工人日报 2023-11-04 打工人日报 2023-11-03 打工人日报 2023-11-02 打工人日报 2023-11-01 打工人日报 2023-10-31 打工人日报 2023-10-30 打工人日报 2023-10-29 打工人日报 2023-10-28 打工人日报 2023-10-27 打工人日报 2023-10-26 打工人日报 2023-10-25 打工人日报 2023-10-24 打工人日报 2023-10-23 打工人日报 2023-10-22 打工人日报 2023-10-21 打工人日报 2023-10-20 打工人日报 2023-10-19 打工人日报 2023-10-18 打工人日报 2023-10-17 打工人日报 2023-10-16 打工人日报 2023-10-15 打工人日报 2023-10-14 打工人日报 2023-10-13 打工人日报 2023-10-12 打工人日报 2023-10-11 打工人日报 2023-10-10 打工人日报 2023-10-09 打工人日报 2023-10-07 打工人日报 2023-10-06 打工人日报 2023-10-05 打工人日报 2023-10-04 打工人日报 2023-10-03 打工人日报 2023-10-02 打工人日报 2023-10-01 打工人日报 2023-09-30 打工人日报 2023-09-29 打工人日报 2023-09-28 打工人日报 2023-09-27 打工人日报 2023-09-26 打工人日报 2023-09-25 打工人日报 2023-09-24 打工人日报 2023-09-23 打工人日报 2023-09-22 打工人日报 2023-09-21 打工人日报 2023-09-20 打工人日报 2023-09-19 打工人日报 2023-09-18 打工人日报 2023-09-17 打工人日报 2023-09-16 打工人日报 2023-09-15 打工人日报 2023-09-14 打工人日报 2023-09-13 打工人日报 2023-09-12 打工人日报 2023-09-11 打工人日报
github 国内代理访问下载
2023-04-11 · via jobcher on 打工人日志
1#例子
2git clone https://github.jobcher.com/gh/https://github.com/jobcher/blog.git
  1'use strict'
  2
  3/**
  4 * static files (404.html, sw.js, conf.js)
  5 */
  6const ASSET_URL = 'https://jobcher.github.io/'
  7// 前缀,如果自定义路由为example.com/gh/*,将PREFIX改为 '/gh/',注意,少一个杠都会错!
  8const PREFIX = '/gh/'
  9// 分支文件使用jsDelivr镜像的开关,0为关闭,默认关闭
 10const Config = {
 11    jsdelivr: 0
 12}
 13
 14const whiteList = [] // 白名单,路径里面有包含字符的才会通过,e.g. ['/username/']
 15
 16/** @type {RequestInit} */
 17const PREFLIGHT_INIT = {
 18    status: 204,
 19    headers: new Headers({
 20        'access-control-allow-origin': '*',
 21        'access-control-allow-methods': 'GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS',
 22        'access-control-max-age': '1728000',
 23    }),
 24}
 25
 26
 27const exp1 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$/i
 28const exp2 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:blob|raw)\/.*$/i
 29const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i
 30const exp4 = /^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+?\/.+$/i
 31const exp5 = /^(?:https?:\/\/)?gist\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+$/i
 32const exp6 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/tags.*$/i
 33
 34/**
 35 * @param {any} body
 36 * @param {number} status
 37 * @param {Object<string, string>} headers
 38 */
 39function makeRes(body, status = 200, headers = {}) {
 40    headers['access-control-allow-origin'] = '*'
 41    return new Response(body, {status, headers})
 42}
 43
 44
 45/**
 46 * @param {string} urlStr
 47 */
 48function newUrl(urlStr) {
 49    try {
 50        return new URL(urlStr)
 51    } catch (err) {
 52        return null
 53    }
 54}
 55
 56
 57addEventListener('fetch', e => {
 58    const ret = fetchHandler(e)
 59        .catch(err => makeRes('cfworker error:\n' + err.stack, 502))
 60    e.respondWith(ret)
 61})
 62
 63
 64function checkUrl(u) {
 65    for (let i of [exp1, exp2, exp3, exp4, exp5, exp6]) {
 66        if (u.search(i) === 0) {
 67            return true
 68        }
 69    }
 70    return false
 71}
 72
 73/**
 74 * @param {FetchEvent} e
 75 */
 76async function fetchHandler(e) {
 77    const req = e.request
 78    const urlStr = req.url
 79    const urlObj = new URL(urlStr)
 80    let path = urlObj.searchParams.get('q')
 81    if (path) {
 82        return Response.redirect('https://' + urlObj.host + PREFIX + path, 301)
 83    }
 84    // cfworker 会把路径中的 `//` 合并成 `/`
 85    path = urlObj.href.substr(urlObj.origin.length + PREFIX.length).replace(/^https?:\/+/, 'https://')
 86    if (path.search(exp1) === 0 || path.search(exp5) === 0 || path.search(exp6) === 0 || path.search(exp3) === 0 || path.search(exp4) === 0) {
 87        return httpHandler(req, path)
 88    } else if (path.search(exp2) === 0) {
 89        if (Config.jsdelivr) {
 90            const newUrl = path.replace('/blob/', '@').replace(/^(?:https?:\/\/)?github\.com/, 'https://cdn.jsdelivr.net/gh')
 91            return Response.redirect(newUrl, 302)
 92        } else {
 93            path = path.replace('/blob/', '/raw/')
 94            return httpHandler(req, path)
 95        }
 96    } else if (path.search(exp4) === 0) {
 97        const newUrl = path.replace(/(?<=com\/.+?\/.+?)\/(.+?\/)/, '@$1').replace(/^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com/, 'https://cdn.jsdelivr.net/gh')
 98        return Response.redirect(newUrl, 302)
 99    } else {
100        return fetch(ASSET_URL + path)
101    }
102}
103
104
105/**
106 * @param {Request} req
107 * @param {string} pathname
108 */
109function httpHandler(req, pathname) {
110    const reqHdrRaw = req.headers
111
112    // preflight
113    if (req.method === 'OPTIONS' &&
114        reqHdrRaw.has('access-control-request-headers')
115    ) {
116        return new Response(null, PREFLIGHT_INIT)
117    }
118
119    const reqHdrNew = new Headers(reqHdrRaw)
120
121    let urlStr = pathname
122    let flag = !Boolean(whiteList.length)
123    for (let i of whiteList) {
124        if (urlStr.includes(i)) {
125            flag = true
126            break
127        }
128    }
129    if (!flag) {
130        return new Response("blocked", {status: 403})
131    }
132    if (urlStr.startsWith('github')) {
133        urlStr = 'https://' + urlStr
134    }
135    const urlObj = newUrl(urlStr)
136
137    /** @type {RequestInit} */
138    const reqInit = {
139        method: req.method,
140        headers: reqHdrNew,
141        redirect: 'manual',
142        body: req.body
143    }
144    return proxy(urlObj, reqInit)
145}
146
147
148/**
149 *
150 * @param {URL} urlObj
151 * @param {RequestInit} reqInit
152 */
153async function proxy(urlObj, reqInit) {
154    const res = await fetch(urlObj.href, reqInit)
155    const resHdrOld = res.headers
156    const resHdrNew = new Headers(resHdrOld)
157
158    const status = res.status
159
160    if (resHdrNew.has('location')) {
161        let _location = resHdrNew.get('location')
162        if (checkUrl(_location))
163            resHdrNew.set('location', PREFIX + _location)
164        else {
165            reqInit.redirect = 'follow'
166            return proxy(newUrl(_location), reqInit)
167        }
168    }
169    resHdrNew.set('access-control-expose-headers', '*')
170    resHdrNew.set('access-control-allow-origin', '*')
171
172    resHdrNew.delete('content-security-policy')
173    resHdrNew.delete('content-security-policy-report-only')
174    resHdrNew.delete('clear-site-data')
175
176    return new Response(res.body, {
177        status,
178        headers: resHdrNew,
179    })
180}
1git config --global https.proxy http://127.0.0.1:1080
2#取消设置
3git config --global --unset https.proxy