peterxcli commented on code in PR #10031: URL: https://github.com/apache/ozone/pull/10031#discussion_r3060072282
########## hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3ConditionalRequest.java: ########## @@ -0,0 +1,246 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.ozone.s3.endpoint; + +import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_REQUEST; +import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.PRECOND_FAILED; +import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError; +import static org.apache.hadoop.ozone.s3.util.S3Utils.stripQuotes; + +import java.text.ParseException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.OptionalLong; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; +import javax.ws.rs.core.Response.Status; +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.client.OzoneKey; +import org.apache.hadoop.ozone.s3.exception.OS3Exception; +import org.apache.hadoop.ozone.s3.util.S3Consts; +import org.apache.hadoop.ozone.web.utils.OzoneUtils; + +/** + * Shared parsing and evaluation for S3 conditional request headers. + */ +final class S3ConditionalRequest { + + private S3ConditionalRequest() { + } + + static Response evaluateReadPreconditions(HttpHeaders headers, + String keyPath, OzoneKey key) throws OS3Exception { + String currentETag = key.getMetadata().get(OzoneConsts.ETAG); + String ifMatch = headers.getHeaderString(S3Consts.IF_MATCH_HEADER); + if (ifMatch != null && !eTagMatches(ifMatch, currentETag)) { + throw newError(PRECOND_FAILED, keyPath); + } + + String ifUnmodifiedSince = headers.getHeaderString( + S3Consts.IF_UNMODIFIED_SINCE_HEADER); + if (ifMatch == null && ifUnmodifiedSince != null + && !matchesIfUnmodifiedSince(key, ifUnmodifiedSince)) { + throw newError(PRECOND_FAILED, keyPath); Review Comment: the if-match header parsing and verification has done before this step. per https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html#API_GetObject_RequestBody > [If-Unmodified-Since](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html#API_GetObject_RequestSyntax) Return the object only if it has not been modified since the specified time; otherwise, return a 412 Precondition Failed error. > > If both of the If-Match and If-Unmodified-Since headers are present in the request as follows: If-Match condition evaluates to true, and; If-Unmodified-Since condition evaluates to false; then, S3 returns 200 OK and the data requested. > > For more information about conditional requests, see [RFC 7232](https://tools.ietf.org/html/rfc7232). **"If-Match condition evaluates to true, and; If-Unmodified-Since condition evaluates to false; then, S3 returns 200 OK and the data requested"** means: if if-match header pass, then we dont need to care about the `If-Unmodified-Since` header -- 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]
