Skip to content

Commit

Permalink
feat: add an x-redirected-url header to inform clients of redirects (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
billiegoose authored Nov 17, 2019
1 parent 476b3e2 commit 6ba7aaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const exposeHeaders = [
'transfer-encoding',
'vary',
'x-github-request-id',
'x-redirected-url',
]
const allowMethods = [
'POST',
Expand Down Expand Up @@ -108,6 +109,11 @@ module.exports = ({ origin, insecure_origins = [], authorization = noop } = {})
}
}

// GitHub uses user-agent sniffing for git/* and changes its behavior which is frustrating
if (!headers['user-agent'] || !headers['user-agent'].startsWith('git/')) {
headers['user-agent'] = 'git/@isomorphic-git/cors-proxy'
}

let p = u.path
let parts = p.match(/\/([^\/]*)\/(.*)/)
let pathdomain = parts[1]
Expand All @@ -128,6 +134,9 @@ module.exports = ({ origin, insecure_origins = [], authorization = noop } = {})
if (f.headers.has(h)) {
res.setHeader(h, f.headers.get(h))
}
if (f.redirected) {
res.setHeader('x-redirected-url', f.url)
}
}
f.body.pipe(res)
})
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"micro": "^9.3.3",
"micro-cors": "0.1.1",
"minimisted": "^2.0.0",
"node-fetch": "^2.3.0",
"node-fetch": "^2.6.0",
"tree-kill": "^1.2.1"
},
"now": {
Expand Down

0 comments on commit 6ba7aaa

Please # to comment.