diff --git a/src/origin/request/index.py b/src/origin/request/index.py index 6228156..d6cb0e1 100644 --- a/src/origin/request/index.py +++ b/src/origin/request/index.py @@ -46,7 +46,6 @@ ]) expiration_re = re.compile(r'\s*([\w-]+)="([^"]*)"(:?,|$)') -ms_subdir_re = re.compile(r'^/[_0-9a-zA-Z-]+(/wp-.*)$') API_VERSION = 2 @@ -130,7 +129,6 @@ class XParams: bypass_minifier_patterns: str expiration_margin: int basedir: str - is_multisite_subdir: bool @dataclasses.dataclass @@ -208,7 +206,6 @@ def __init__( bypass_minifier_path_spec: Optional[PathSpec], expiration_margin: int, basedir: str, - is_multisite_subdir: bool, ): self.log = log self.region = region @@ -224,7 +221,6 @@ def __init__( self.bypass_minifier_path_spec = bypass_minifier_path_spec self.expiration_margin = datetime.timedelta(seconds=expiration_margin) self.basedir = basedir - self.is_multisite_subdir = is_multisite_subdir @classmethod def from_lambda( @@ -245,8 +241,6 @@ def from_lambda( bypass_minifier_patterns: str = get_header_or( req, 'x-env-bypass-minifier-patterns') basedir: str = get_header_or(req, 'x-env-basedir') - is_multisite_subdir: bool = bool( - get_header_or(req, 'x-env-is-multisite-subdir')) except KeyError as e: log.warning({ MESSAGE: 'environment variable not found', @@ -264,8 +258,7 @@ def from_lambda( temp_resp_max_age=temp_resp_max_age, bypass_minifier_patterns=bypass_minifier_patterns, expiration_margin=expiration_margin, - basedir=basedir, - is_multisite_subdir=is_multisite_subdir) + basedir=basedir) if server_key not in cls.instances: sqs = boto3.client('sqs', region_name=region) @@ -286,8 +279,7 @@ def from_lambda( temp_resp_max_age=temp_resp_max_age, bypass_minifier_path_spec=path_spec, expiration_margin=expiration_margin, - basedir=basedir, - is_multisite_subdir=is_multisite_subdir) + basedir=basedir) return cls.instances[server_key] @@ -471,10 +463,6 @@ def process(self, path: str, accept_header: str) -> FieldUpdate: }) path = path[len(self.basedir):] - if self.is_multisite_subdir: - if m := ms_subdir_re.match(path): - path = m.group(1) - if self.bypass_minifier_path_spec is not None and ( self.bypass_minifier_path_spec.match_file(path)): return self.respond_with_original() diff --git a/src/origin/request/test_index.py b/src/origin/request/test_index.py index b21e347..49d9a8b 100644 --- a/src/origin/request/test_index.py +++ b/src/origin/request/test_index.py @@ -81,7 +81,7 @@ def generate_safe_random_string() -> str: def create_img_server( log: Logger, name: str, expiration_margin: int, key_prefix: str, - basedir: str, is_multisite_subdir: bool) -> ImgServer: + basedir: str) -> ImgServer: account_id = read_test_config('aws-account-id') sqs_name = f'test-{name}-{generate_safe_random_string()}' @@ -109,8 +109,7 @@ def create_img_server( bypass_minifier_path_spec=PathSpec.from_lines( GitWildMatchPattern, get_bypass_minifier_patterns(key_prefix)), expiration_margin=expiration_margin, - basedir=basedir, - is_multisite_subdir=is_multisite_subdir) + basedir=basedir) def get_test_sqs_queue_name_from_url(sqs_queue_url: str) -> str: @@ -123,10 +122,9 @@ def create_test_environment( expiration_margin: int, key_prefix: str, basedir: str, - is_multisite_subdir: bool, ) -> ImgServer: img_server = create_img_server( - log, name, expiration_margin, key_prefix, basedir, is_multisite_subdir) + log, name, expiration_margin, key_prefix, basedir) img_server.sqs.create_queue( QueueName=get_test_sqs_queue_name_from_url(img_server.sqs_queue_url)) return img_server @@ -217,7 +215,7 @@ def setUp(self) -> None: self._img_server = create_test_environment( self._log, 'imglambda', self.get_expiration_margin(), self._key_prefix, - self.get_basedir(), self.is_multisite_subdir()) + self.get_basedir()) def get_expiration_margin(self) -> int: return 10 @@ -225,21 +223,14 @@ def get_expiration_margin(self) -> int: def get_basedir(self) -> str: return '' - def is_multisite_subdir(self) -> bool: - return False - - def put_original( - self, name: str, mime: str, dir: str = '') -> datetime.datetime: + def put_original(self, name: str, mime: str) -> datetime.datetime: return put_original( - self._img_server, f'{dir}{self._key_prefix}{name}', name, mime) + self._img_server, f'{self._key_prefix}{name}', name, mime) def put_generated( - self, - name: str, - mime: str, - timestamp: Optional[datetime.datetime], - dir: str = '') -> None: - key = f'{self._img_server.generated_key_prefix}{dir}{self._key_prefix}{name}' + self, name: str, mime: str, + timestamp: Optional[datetime.datetime]) -> None: + key = f'{self._img_server.generated_key_prefix}{self._key_prefix}{name}' put_generated(self._img_server, key, name, mime, timestamp) @@ -264,11 +255,11 @@ def assert_sqs_message(self, key: str) -> None: }, }, self.receive_sqs_message()) - def to_path(self, name: str, dir: str = '') -> str: - return f'/{dir}{self._key_prefix}{name}' + def to_path(self, name: str) -> str: + return f'/{self._key_prefix}{name}' - def to_uri(self, name: str, dir: str = '') -> str: - return f'/{self._img_server.generated_key_prefix}{dir}{self._key_prefix}{name}' + def to_uri(self, name: str) -> str: + return f'/{self._img_server.generated_key_prefix}{self._key_prefix}{name}' def tearDown(self) -> None: clean_test_environment(self._img_server) @@ -303,40 +294,6 @@ def test_no_basedir(self) -> None: self.assert_no_sqs_message() -class ImgserverMultisiteSubdirTestCase(BaseTestCase): - - def is_multisite_subdir(self) -> bool: - return True - - def test_subdir_wp(self) -> None: - ts = self.put_original(JPG_NAME, JPEG_MIME, 'wp-content/uploads/') - self.put_generated(JPG_WEBP_NAME, JPEG_MIME, ts, 'wp-content/uploads/') - - update = self._img_server.process( - self.to_path(JPG_NAME, 'blog1/wp-content/uploads/'), - CHROME_ACCEPT_HEADER) - self.assertEqual( - FieldUpdate( - res_cache_control=CACHE_CONTROL_PERM, - origin_domain=self._img_server.generated_domain, - uri=self.to_uri(f'{JPG_NAME}.webp', 'wp-content/uploads/')), update) - self.assert_no_sqs_message() - - def test_subdir(self) -> None: - ts = self.put_original(JPG_NAME, JPEG_MIME) - self.put_generated(JPG_WEBP_NAME, JPEG_MIME, ts) - - update = self._img_server.process( - self.to_path(JPG_NAME), CHROME_ACCEPT_HEADER) - self.assertEqual( - FieldUpdate( - res_cache_control=CACHE_CONTROL_PERM, - origin_domain=self._img_server.generated_domain, - uri=self.to_uri(f'{JPG_NAME}.webp'), - ), update) - self.assert_no_sqs_message() - - class ImgserverExpiredTestCase(BaseTestCase): def get_expiration_margin(self) -> int: