Skip to content

Commit 6ba7aaa

Browse files
authored
feat: add an x-redirected-url header to inform clients of redirects (#7)
1 parent 476b3e2 commit 6ba7aaa

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

middleware.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const exposeHeaders = [
3939
'transfer-encoding',
4040
'vary',
4141
'x-github-request-id',
42+
'x-redirected-url',
4243
]
4344
const allowMethods = [
4445
'POST',
@@ -108,6 +109,11 @@ module.exports = ({ origin, insecure_origins = [], authorization = noop } = {})
108109
}
109110
}
110111

112+
// GitHub uses user-agent sniffing for git/* and changes its behavior which is frustrating
113+
if (!headers['user-agent'] || !headers['user-agent'].startsWith('git/')) {
114+
headers['user-agent'] = 'git/@isomorphic-git/cors-proxy'
115+
}
116+
111117
let p = u.path
112118
let parts = p.match(/\/([^\/]*)\/(.*)/)
113119
let pathdomain = parts[1]
@@ -128,6 +134,9 @@ module.exports = ({ origin, insecure_origins = [], authorization = noop } = {})
128134
if (f.headers.has(h)) {
129135
res.setHeader(h, f.headers.get(h))
130136
}
137+
if (f.redirected) {
138+
res.setHeader('x-redirected-url', f.url)
139+
}
131140
}
132141
f.body.pipe(res)
133142
})

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"micro": "^9.3.3",
2424
"micro-cors": "0.1.1",
2525
"minimisted": "^2.0.0",
26-
"node-fetch": "^2.3.0",
26+
"node-fetch": "^2.6.0",
2727
"tree-kill": "^1.2.1"
2828
},
2929
"now": {

0 commit comments

Comments
 (0)