chungen0126 commented on code in PR #10138:
URL: https://github.com/apache/ozone/pull/10138#discussion_r3195595470
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/CommonHeadersContainerResponseFilter.java:
##########
@@ -44,5 +55,54 @@ public void filter(ContainerRequestContext
containerRequestContext,
containerResponseContext.getHeaders()
.add("x-amz-request-id", requestIdentifier.getRequestId());
+ addCorsHeaders(containerRequestContext, containerResponseContext);
+ }
+
+ private void addCorsHeaders(ContainerRequestContext requestContext,
+ ContainerResponseContext responseContext) {
+ String origin = requestContext.getHeaderString(S3Consts.ORIGIN_HEADER);
+ if (StringUtils.isBlank(origin)
+ || "OPTIONS".equalsIgnoreCase(requestContext.getMethod())) {
+ return;
+ }
+
+ String bucketName = getBucketName(requestContext);
+ if (StringUtils.isBlank(bucketName)) {
+ return;
+ }
+
+ try {
+ OzoneBucket bucket = getCachedBucket(requestContext, bucketName);
+ if (bucket == null) {
+ return;
+ }
+ Optional<CorsRule> rule = S3CorsHeaders.findMatchingRule(
+ bucket.getCorsConfiguration(), origin, requestContext.getMethod(),
+ null);
+ rule.ifPresent(corsRule -> S3CorsHeaders.applyHeaders(
+ responseContext.getHeaders(), corsRule, origin, null, false));
Review Comment:
nit: Both `findMatchingRule` and `S3CorsHeaders.applyHeaders()` are being
called here.
However, there seems to be some overlapping logic between the
`requestedHeadersMatch` inside `findMatchingRule` and the
`allowedHeadersForResponse()` inside `3CorsHeaders.applyHeaders()`.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3RequestContext.java:
##########
@@ -53,6 +58,27 @@ OzoneVolume getVolume() throws IOException {
return volume;
}
+ OzoneBucket getBucket(String bucketName) throws IOException {
+ OzoneBucket bucket = buckets.get(bucketName);
+ if (bucket == null) {
+ bucket = getVolume().getBucket(bucketName);
+ endpoint.cacheBucket(bucketName, bucket);
+ buckets.put(bucketName, bucket);
+ }
+ return bucket;
+ }
+
+ OzoneBucket getS3Bucket(String bucketName) throws IOException {
+ OzoneBucket bucket = buckets.get(bucketName);
+ if (bucket == null) {
+ ObjectStore objectStore = endpoint.getClient().getObjectStore();
+ bucket = objectStore.getS3Bucket(bucketName);
+ endpoint.cacheBucket(bucketName, bucket);
+ buckets.put(bucketName, bucket);
+ }
+ return bucket;
+ }
Review Comment:
Could you please explain the differences between these two methods and when
to use each one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]