def params(self): """The params that should be used to override the request params. For POST requests, the parameters are assumed to be encoded in the request body. The value of the params can be a dictionary or list of sublists, with each sublist having two elements - a URL pattern and params. Where a param in the dictionary exists in the request, the dictionary value will overwrite the one in the request. Where a param in the dictionary does not exist in the request, it will be added to the request as a new param. To filter out a param from the request, set that param in the dictionary to None. For example: params = {'foo': 'bar'} params = [ ('.*somewhere.com.*', {'foo': 'bar'}), ('*.somewhere-else.com.*', {'x': 'y'}), ] """ with self._lock: if is_list_alike(self._params): return self._params else: return dict(self._params)
def headers(self): """The header overrides for outgoing browser requests. The value of the headers can be a dictionary or list of sublists, with each sublist having two elements - a URL pattern and headers. Where a header in the dictionary exists in the request, the dictionary value will overwrite the one in the request. Where a header in the dictionary does not exist in the request, it will be added to the request as a new header. To filter out a header from the request, set that header in the dictionary to None. Header names are case insensitive. For response headers, prefix the header name with 'response:'. For example: headers = { 'User-Agent': 'Firefox', 'response:Cache-Control': 'none' } headers = [ ('.*somewhere.com.*', {'User-Agent': 'Firefox', 'response:Cache-Control': 'none'}), ('*.somewhere-else.com.*', {'User-Agent': 'Chrome'}) """ with self._lock: if is_list_alike(self._headers): return self._headers else: return dict(self._headers)
def in_scope(self, scopes, url): if not scopes: return True elif not is_list_alike(scopes): scopes = [scopes] for scope in scopes: match = re.search(scope, url) if match: return True return False
def _get_matching_overrides(self, overrides, url): with self._lock: # If the overrides is tuple or list, we need to match against the URL if is_list_alike(overrides): for pat, ov in overrides: match = re.search(pat, url) if match: return ov else: return overrides
def in_scope(self, request): if request.method in self.proxy.options.get('ignore_http_methods', ['OPTIONS']): return False scopes = self.proxy.scopes if not scopes: return True elif not is_list_alike(scopes): scopes = [scopes] for scope in scopes: match = re.search(scope, request.url) if match: return True return False