wwj6591812 commented on code in PR #8219:
URL: https://github.com/apache/paimon/pull/8219#discussion_r3445759716
##########
paimon-api/src/main/java/org/apache/paimon/rest/HttpClientUtils.java:
##########
@@ -86,9 +88,69 @@ private static HttpClientConnectionManager
configureConnectionManager() {
public static InputStream getAsInputStream(String uri) throws IOException {
HttpGet httpGet = new HttpGet(uri);
CloseableHttpResponse response = DEFAULT_HTTP_CLIENT.execute(httpGet);
- if (response.getCode() != 200) {
- throw new RuntimeException("HTTP error code: " +
response.getCode());
+ int statusCode = response.getCode();
+ if (statusCode != HttpStatus.SC_OK) {
+ try {
+ throw httpError(statusCode);
+ } finally {
+ response.close();
+ }
}
return response.getEntity().getContent();
}
+
+ /**
+ * Checks whether an HTTP resource exists. HEAD is attempted first; when
HEAD does not return
+ * 200, a lightweight GET with {@code Range: bytes=0-0} is used to verify
readability. This
+ * avoids treating signed or GET-only URLs as missing when HEAD is
rejected or returns a
+ * different status than GET.
+ */
+ public static boolean exists(String uri) throws IOException {
+ int headStatusCode = headStatusCode(uri);
+ if (headStatusCode == HttpStatus.SC_OK) {
+ return true;
+ }
+ int rangeStatusCode = getRangeStatusCode(uri);
+ if (rangeStatusCode == HttpStatus.SC_OK
Review Comment:
Thanks for catching this, @JingsongLi .
You're right — for a zero-length HTTP resource, Range: bytes=0-0 can
legitimately return 416 even though a normal GET would succeed with an empty
body, and treating that as an error breaks exists() for existing empty blobs.
I've updated HttpClientUtils.exists() to treat HTTP 416 from the range probe
as an existing resource, and added
testExistsTreatsEmptyResourceAsExistingWhenRangeReturns416 (HEAD disabled +
empty response + range GET returns 416). Please take another look when you have
a chance.
--
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]