diff --git a/README.md b/README.md index 6dc35ab..0b288ac 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,10 @@ > 例如百度云提供 `s3.bj.bcebos.com` 和 `.s3.bj.bcebos.com` 两种 Endpoint,请填写`s3.bj.bcebos.com`。 +### 启用分块传输编码 + +默认关闭。若经过反向代理(如 Cloudflare Tunnel、Ingress)导致请求被改为 `Transfer-Encoding: chunked` 并移除 `Content-Length`,服务端签名校验可能不一致而返回 403,可开启该选项以提升兼容性。 + ### Access Key & Access Secret 与服务商自己 API 的 Access Key 和 Access Secret 相同,详情查看对应服务商的文档。 diff --git a/src/main/java/run/halo/s3os/S3LinkServiceImpl.java b/src/main/java/run/halo/s3os/S3LinkServiceImpl.java index 8e81459..7f64fcc 100644 --- a/src/main/java/run/halo/s3os/S3LinkServiceImpl.java +++ b/src/main/java/run/halo/s3os/S3LinkServiceImpl.java @@ -31,7 +31,7 @@ import run.halo.app.extension.ListOptions; import run.halo.app.extension.MetadataUtil; import run.halo.app.extension.ReactiveExtensionClient; -import run.halo.app.extension.index.query.QueryFactory; +import run.halo.app.extension.index.query.Queries; import run.halo.app.extension.router.selector.FieldSelector; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.HeadObjectRequest; @@ -91,7 +91,7 @@ public Mono listObjects(String policyName, String continuationToke // 获取已经关联的附件并标记 ListOptions listOptions = new ListOptions(); listOptions.setFieldSelector( - FieldSelector.of(QueryFactory.equal("spec.policyName", policyName))); + FieldSelector.of(Queries.equal("spec.policyName", policyName))); return client.listAll(Attachment.class, listOptions, Sort.unsorted()) .doOnNext(attachment -> { S3ListResult.ObjectVo objectVo = @@ -133,7 +133,7 @@ private Mono> getExistingAttachments(Set objectKeys, String policyName) { ListOptions listOptions = new ListOptions(); listOptions.setFieldSelector( - FieldSelector.of(QueryFactory.equal("spec.policyName", policyName))); + FieldSelector.of(Queries.equal("spec.policyName", policyName))); return client.listAll(Attachment.class, listOptions, Sort.unsorted()) .filter(attachment -> StringUtils.isNotBlank( MetadataUtil.nullSafeAnnotations(attachment).get(S3OsAttachmentHandler.OBJECT_KEY)) diff --git a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java index cf4af2c..c55f970 100644 --- a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java +++ b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java @@ -314,7 +314,7 @@ S3Client buildS3Client(S3OsProperties properties) { .credentialsProvider(() -> AwsBasicCredentials.create(properties.getAccessKey(), properties.getAccessSecret())) .serviceConfiguration(S3Configuration.builder() - .chunkedEncodingEnabled(false) + .chunkedEncodingEnabled(Boolean.TRUE.equals(properties.getEnableChunkedEncoding())) .pathStyleAccessEnabled(properties.getEnablePathStyleAccess()) .build()) .build(); @@ -328,7 +328,7 @@ private S3Presigner buildS3Presigner(S3OsProperties properties) { .credentialsProvider(() -> AwsBasicCredentials.create(properties.getAccessKey(), properties.getAccessSecret())) .serviceConfiguration(S3Configuration.builder() - .chunkedEncodingEnabled(false) + .chunkedEncodingEnabled(Boolean.TRUE.equals(properties.getEnableChunkedEncoding())) .pathStyleAccessEnabled(properties.getEnablePathStyleAccess()) .build()) .build(); diff --git a/src/main/java/run/halo/s3os/S3OsProperties.java b/src/main/java/run/halo/s3os/S3OsProperties.java index 3d10e4a..4ed95b4 100644 --- a/src/main/java/run/halo/s3os/S3OsProperties.java +++ b/src/main/java/run/halo/s3os/S3OsProperties.java @@ -19,6 +19,8 @@ public class S3OsProperties { private Boolean enablePathStyleAccess = false; + private Boolean enableChunkedEncoding = false; + private String endpoint; private String accessKey; diff --git a/src/main/resources/extensions/policy-template-s3os.yaml b/src/main/resources/extensions/policy-template-s3os.yaml index 5133af7..70b9608 100644 --- a/src/main/resources/extensions/policy-template-s3os.yaml +++ b/src/main/resources/extensions/policy-template-s3os.yaml @@ -47,6 +47,16 @@ spec: value: true value: false validation: required + - $formkit: select + name: enableChunkedEncoding + label: 启用分块传输编码 + options: + - label: 关闭 + value: false + - label: 开启 + value: true + value: false + help: 反向代理可能会移除 Content-Length 请求头,从而导致签名不一致发生 403 错误,可以尝试开启此选项 - $formkit: text name: endpoint label: EndPoint