|
45 | 45 | SIGNATURE_V4_PARAMS, |
46 | 46 | ) |
47 | 47 | from localstack.services.s3.utils import ( |
48 | | - S3_VIRTUAL_HOST_FORWARDED_HEADER, |
49 | 48 | capitalize_header_name_from_snake_case, |
50 | 49 | extract_bucket_name_and_key_from_headers_and_path, |
51 | | - forwarded_from_virtual_host_addressed_request, |
52 | 50 | is_bucket_name_valid, |
53 | 51 | is_presigned_url_request, |
54 | 52 | uses_host_addressing, |
@@ -567,34 +565,21 @@ def __init__(self, context: RequestContext): |
567 | 565 | self._query_parameters |
568 | 566 | ) |
569 | 567 |
|
570 | | - if forwarded_from_virtual_host_addressed_request(self._headers): |
571 | | - # FIXME: maybe move this so it happens earlier in the chain when using virtual host? |
572 | | - if not is_bucket_name_valid(self._bucket): |
573 | | - raise InvalidBucketName(BucketName=self._bucket) |
574 | | - netloc = self._headers.get(S3_VIRTUAL_HOST_FORWARDED_HEADER) |
575 | | - self.host = netloc |
576 | | - self._original_host = netloc |
577 | | - self.signed_headers["host"] = netloc |
578 | | - # the request comes from the Virtual Host router, we need to remove the bucket from the path |
| 568 | + netloc = urlparse.urlparse(self.request.url).netloc |
| 569 | + self.host = netloc |
| 570 | + self._original_host = netloc |
| 571 | + if (host_addressed := uses_host_addressing(self._headers)) and not is_bucket_name_valid( |
| 572 | + self._bucket |
| 573 | + ): |
| 574 | + raise InvalidBucketName(BucketName=self._bucket) |
| 575 | + |
| 576 | + if not host_addressed and not self.request.path.startswith(f"/{self._bucket}"): |
| 577 | + # if in path style, check that the path starts with the bucket |
| 578 | + # our path has been sanitized, we should use the un-sanitized one |
579 | 579 | splitted_path = self.request.path.split("/", maxsplit=2) |
580 | | - self.path = f"/{splitted_path[-1]}" |
581 | | - |
| 580 | + self.path = f"/{self._bucket}/{splitted_path[-1]}" |
582 | 581 | else: |
583 | | - netloc = urlparse.urlparse(self.request.url).netloc |
584 | | - self.host = netloc |
585 | | - self._original_host = netloc |
586 | | - if (host_addressed := uses_host_addressing(self._headers)) and not is_bucket_name_valid( |
587 | | - self._bucket |
588 | | - ): |
589 | | - raise InvalidBucketName(BucketName=self._bucket) |
590 | | - |
591 | | - if not host_addressed and not self.request.path.startswith(f"/{self._bucket}"): |
592 | | - # if in path style, check that the path starts with the bucket |
593 | | - # our path has been sanitized, we should use the un-sanitized one |
594 | | - splitted_path = self.request.path.split("/", maxsplit=2) |
595 | | - self.path = f"/{self._bucket}/{splitted_path[-1]}" |
596 | | - else: |
597 | | - self.path = self.request.path |
| 582 | + self.path = self.request.path |
598 | 583 |
|
599 | 584 | # we need to URL encode the path, as the key needs to be urlencoded for the signature to match |
600 | 585 | self.path = urlparse.quote(self.path) |
|
0 commit comments