From b6c71d62fd976c1b63f97c635bc10611f916026b Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 5 Oct 2018 12:13:12 +0800 Subject: [PATCH] add provide-variables to IfBlock, modifier ^~ to LocationBlock --- gixy/directives/block.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gixy/directives/block.py b/gixy/directives/block.py index 5e5b1ed..9e9b008 100644 --- a/gixy/directives/block.py +++ b/gixy/directives/block.py @@ -111,7 +111,7 @@ class LocationBlock(Block): @cached_property def variables(self): - if not self.modifier or self.modifier not in ('~', '~*'): + if not self.modifier or self.modifier not in ('~', '~*', '^~'): return [] regexp = Regexp(self.path, case_sensitive=self.modifier == '~') @@ -124,6 +124,7 @@ class LocationBlock(Block): class IfBlock(Block): nginx_name = 'if' self_context = False + provide_variables = True def __init__(self, name, args): super(IfBlock, self).__init__(name, args) @@ -143,6 +144,17 @@ class IfBlock(Block): else: raise Exception('Unknown "if" definition, args: {0!r}'.format(args)) + @cached_property + def variables(self): + if self.operand != '~': + return [] + + regexp = Regexp(self.value, case_sensitive=self.operand == '~') + result = [] + for name, group in regexp.groups.items(): + result.append(Variable(name=name, value=group, boundary=None, provider=self)) + return result + def __str__(self): return '{name} ({args}) {{'.format(name=self.name, args=' '.join(self.args))