nastra commented on code in PR #10753:
URL: https://github.com/apache/iceberg/pull/10753#discussion_r1871404552


##########
core/src/main/java/org/apache/iceberg/rest/HTTPRequest.java:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.iceberg.rest;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import javax.annotation.ParametersAreNonnullByDefault;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.immutables.value.Value;
+
+/** Represents an HTTP request. */
+@Value.Style(
+    set = "*",
+    put = "set*",
+    putAll = "add*",
+    create = "new",
+    toImmutable = "build",
+    redactedMask = "****",
+    depluralize = true)
+@Value.Modifiable
+@Value.Immutable(builder = false)
+@ParametersAreNonnullByDefault
+@SuppressWarnings({"ImmutablesStyle", "SafeLoggingPropagation"})
+public abstract class HTTPRequest {
+
+  public enum HTTPMethod {
+    GET,
+    HEAD,
+    POST,
+    DELETE
+  }
+
+  /**
+   * Returns the base URI configured at the REST client level. The base URI is 
used to construct the
+   * full {@link #requestUri()}.
+   */
+  @Value.Parameter(order = 0)
+  protected abstract URI baseUri();
+
+  /**
+   * Returns the full URI of this request. The URI is constructed from the 
base URI, path, and query
+   * parameters. It cannot be modified directly.
+   */
+  @Value.Lazy
+  public URI requestUri() {
+    return RESTUtil.buildRequestUri(this);
+  }
+
+  /** Returns the HTTP method of this request. */
+  @Value.Parameter(order = 1)
+  public abstract HTTPMethod method();
+
+  /** Returns the path of this request. */
+  @Value.Parameter(order = 2)
+  public abstract String path();
+
+  /** Returns the query parameters of this request. */
+  @Value.Parameter(order = 3)
+  public abstract Map<String, String> parameters();
+
+  /** Returns all the headers of this request. The map is case-sensitive! */
+  @Value.Parameter(order = 4)
+  @Value.Redacted
+  public abstract Map<String, List<String>> headers();
+
+  /** Returns the header values of the given name. */
+  public List<String> headers(String name) {
+    return headers().getOrDefault(name, List.of());
+  }
+
+  /** Returns whether the request contains a header with the given name. */
+  public boolean containsHeader(String name) {
+    return !headers(name).isEmpty();
+  }
+
+  /** Returns the raw, unencoded request body. */
+  @Nullable
+  @Value.Parameter(order = 5)
+  @Value.Redacted
+  public abstract Object body();
+
+  /** Returns the encoded request body as a string. */
+  @Value.Default
+  @Nullable
+  @Value.Redacted
+  public String encodedBody() {
+    return RESTUtil.encodeRequestBody(this);
+  }
+
+  /**
+   * Returns the {@link ObjectMapper} to use for encoding the request body. 
The default is {@link
+   * RESTObjectMapper#mapper()}.
+   */
+  @Value.Default
+  protected ObjectMapper mapper() {
+    return RESTObjectMapper.mapper();
+  }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static Builder builder(
+      URI baseUri,
+      HTTPMethod method,
+      String path,
+      @Nullable Map<String, String> queryParams,
+      @Nullable Map<String, String> headers,
+      @Nullable Object body,
+      @Nullable ObjectMapper mapper) {
+    Builder builder = 
builder().baseUri(baseUri).method(method).path(path).body(body);
+    if (queryParams != null) {
+      queryParams.forEach(builder::setParameter);
+    }
+    if (headers != null) {
+      headers.forEach(builder::setHeader);
+    }
+    if (mapper != null) {
+      builder.mapper(mapper);
+    }
+    return builder;
+  }
+
+  /** A modifiable builder for {@link HTTPRequest}. */
+  public static class Builder extends ModifiableHTTPRequest {

Review Comment:
   what I mean is whether we can get around without having a modifyable builder



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to