Pass <local> to target browser as-is. Avoid <local> in default config.

See the added comments as well as #443 for discussion.

Newly created proxy profiles will have 127.0.0.1, ::1 and localhost in
bypass list by default, instead of <local> in hope that fewer users
will be trapped in the IPv6 literals gotcha.
This commit is contained in:
FelisCatus 2016-03-17 16:18:25 +08:00
parent 374b8a42c5
commit b67790eb83
6 changed files with 88 additions and 17 deletions

View File

@ -352,7 +352,16 @@ module.exports = exports =
return false if cache.ip? and not @match cache.ip, request
if cache.host?
if cache.host == '<local>'
return request.host in @localHosts
# https://code.google.com/p/chromium/codesearch#chromium/src/net/proxy/proxy_bypass_rules.cc&sq=package:chromium&l=67
# We align with Chromium's behavior of bypassing 127.0.0.1, ::1 as
# well as any host without dots.
#
# This, however, will match IPv6 literals who also don't have dots.
return (
request.host == '127.0.0.1' or
request.host == '::1' or
request.host.indexOf('.') < 0
)
else
return false if not cache.host.test(request.host)
return false if cache.url? and !cache.url.test(request.url)
@ -370,12 +379,22 @@ module.exports = exports =
)
return new U2.AST_Binary(
left: new U2.AST_Binary(
left: hostEquals '[::1]'
left: hostEquals '127.0.0.1'
operator: '||'
right: hostEquals 'localhost'
right: hostEquals '::1'
)
operator: '||'
right: hostEquals '127.0.0.1'
right: new U2.AST_Binary(
left: new U2.AST_Call(
expression: new U2.AST_Dot(
expression: new U2.AST_SymbolRef name: 'host'
property: 'indexOf'
)
args: [new U2.AST_String value: '.']
)
operator: '<'
right: new U2.AST_Number value: 0
)
)
if cache.scheme?
conditions.push new U2.AST_Binary(

View File

@ -237,10 +237,20 @@ module.exports = exports =
'FixedProfile':
includable: true
create: (profile) ->
profile.bypassList ?= [{
profile.bypassList ?= [
{
conditionType: 'BypassCondition'
pattern: '<local>'
}]
pattern: '127.0.0.1'
}
{
conditionType: 'BypassCondition'
pattern: '::1'
}
{
conditionType: 'BypassCondition'
pattern: 'localhost'
}
]
match: (profile, request) ->
if profile.bypassList
for cond in profile.bypassList

View File

@ -31,6 +31,7 @@ describe 'Conditions', ->
printCond = JSON.stringify(condition)
printCompiled = if compiled then 'COMPILED ' else ''
printMatch = if should_match then 'to match' else 'not to match'
console.log(request)
msg = ("expect #{printCompiled}condition #{printCond} " +
"#{printMatch} request #{o_request}")
chai.assert(false, msg)
@ -219,6 +220,31 @@ describe 'Conditions', ->
prefixLength: 0
})
it 'should match 127.0.0.1 when <local> is used', ->
cond =
conditionType: 'BypassCondition'
pattern: '<local>'
testCond(cond, 'http://127.0.0.1:8080/', 'match')
it 'should match [::1] when <local> is used', ->
cond =
conditionType: 'BypassCondition'
pattern: '<local>'
testCond(cond, 'http://[::1]:8080/', 'match')
it 'should match any host without dots when <local> is used', ->
cond =
conditionType: 'BypassCondition'
pattern: '<local>'
testCond(cond, 'http://localhost:8080/', 'match')
testCond(cond, 'http://intranet:8080/', 'match')
testCond(cond, 'http://foobar/', 'match')
testCond(cond, 'http://example.com/', not 'match')
# Intended, see the corresponding code and comments for the reasoning.
testCond(cond, 'http://[::ffff:eeee]/', 'match')
testCond(cond, 'http://[::1.2.3.4]/', not 'match')
describe 'IpCondition', ->
# IpCondition requires isInNetEx or isInNet function provided by the PAC
# runner, which is not available in the unit test. So We can't use testCond

View File

@ -108,10 +108,6 @@ class ChromeOptions extends OmegaTarget.Options
if config['mode'] != 'direct'
rules['bypassList'] = bypassList = []
for rule in profile.bypassList
if rule.pattern == '<local>'
for host in OmegaPac.Conditions.localHosts
bypassList.push(host)
else
bypassList.push(rule.pattern)
config['rules'] = rules
return config

View File

@ -122,8 +122,18 @@ module.exports = (oldOptions, i18n) ->
exampleFixedProfileName = 'Example Profile'
options[OmegaPac.Profiles.nameAsKey(exampleFixedProfileName)] =
bypassList: [
pattern: "<local>"
{
pattern: "127.0.0.1"
conditionType: "BypassCondition"
}
{
pattern: "::1"
conditionType: "BypassCondition"
}
{
pattern: "localhost"
conditionType: "BypassCondition"
}
]
profileType: "FixedProfile"
name: exampleFixedProfileName

View File

@ -10,8 +10,18 @@ module.exports = ->
"-downloadInterval": 1440
"+proxy":
bypassList: [
pattern: "<local>"
{
pattern: "127.0.0.1"
conditionType: "BypassCondition"
}
{
pattern: "::1"
conditionType: "BypassCondition"
}
{
pattern: "localhost"
conditionType: "BypassCondition"
}
]
profileType: "FixedProfile"
name: "proxy"