Skip to content

Commit

Permalink
check host in request headers #162
Browse files Browse the repository at this point in the history
  • Loading branch information
nondanee committed Jul 29, 2019
1 parent c71bb94 commit 24caf36
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ hook.request.before = ctx => {
const req = ctx.req
req.url = (req.url.startsWith('http://') ? '' : (req.socket.encrypted ? 'https:' : 'http:') + '//music.163.com') + req.url
const url = parse(req.url)
if((hook.target.host.includes(url.hostname)) && req.method == 'POST' && (url.path == '/api/linux/forward' || url.path.startsWith('/eapi/'))){
if([url.hostname, req.headers.host].some(host => hook.target.host.includes(host)) && req.method == 'POST' && (url.path == '/api/linux/forward' || url.path.startsWith('/eapi/'))){
return request.read(req)
.then(body => {
req.body = body
Expand Down Expand Up @@ -171,7 +171,7 @@ hook.request.after = ctx => {

hook.connect.before = ctx => {
let url = parse('https://' + ctx.req.url)
if(hook.target.host.includes(url.hostname)){
if([url.hostname, ctx.req.headers.host].some(host => hook.target.host.includes(host))){
if(url.port == 80){
ctx.req.url = `${global.address || 'localhost'}:${global.port[0]}`
ctx.req.local = true
Expand Down

0 comments on commit 24caf36

Please sign in to comment.