feat: S3 client compatibility — virtual-hosted style, CORS, presigned multi-method, ListMultipartUploads, edge case fixes
- Virtual-hosted bucket detection from Host header (extractS3BucketFromHost) - S3 CORS headers + OPTIONS preflight + x-amz-id-2/HostId everywhere - Presigned GET/PUT/HEAD/DELETE via centralized auth (no GET-only restriction) - ListMultipartUploads with DB/xml helpers - UploadPart partNumber range validation (1-10000) - CompleteMultipartUpload ETag matching and ascending order validation - DeleteObjects quiet mode support - CopyObject URL-decode and conditional if-match/if-none-match - encoding-type=url support in ListObjects V1/V2 XML - Safe range-based prefix matching (replaces SQL LIKE) - STREAMING-AWS4-HMAC-SHA256-PAYLOAD → 501 NotImplemented - Traefik wildcard HostRegex for virtual-hosted style - S3_VHOST_DOMAINS config env var
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const stripPort = (host: string): string => {
|
||||
if (host.startsWith('[')) return host;
|
||||
return host.split(':')[0].toLowerCase().replace(/\.$/, '');
|
||||
};
|
||||
|
||||
const isValidBucketLabel = (bucket: string): boolean =>
|
||||
/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(bucket) &&
|
||||
!bucket.includes('..') &&
|
||||
!bucket.includes('.-') &&
|
||||
!bucket.includes('-.');
|
||||
|
||||
export const extractS3BucketFromHost = (host: string, domains: string[]): string | null => {
|
||||
const normalizedHost = stripPort(host);
|
||||
for (const domain of domains) {
|
||||
const normalizedDomain = stripPort(domain);
|
||||
if (!normalizedDomain || normalizedHost === normalizedDomain) continue;
|
||||
if (!normalizedHost.endsWith(`.${normalizedDomain}`)) continue;
|
||||
|
||||
const bucket = normalizedHost.slice(0, -(normalizedDomain.length + 1));
|
||||
return isValidBucketLabel(bucket) ? bucket : null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user