Copilot commented on code in PR #2326:
URL: https://github.com/apache/maven-resolver/pull/2326#discussion_r4603545449
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/RFC9457Reporter.java:
##########
@@ -86,10 +108,23 @@ protected static String readBody(InputStream is) throws
IOException {
body.write(chunk, 0, read);
remaining -= read;
}
- return body.toString(StandardCharsets.UTF_8.name());
+ return new String(body.toByteArray(), charset);
}
- protected boolean hasRFC9457ContentType(String contentType) {
+ protected static Charset extractCharsetFromContentType(String contentType,
Charset defaultCharset) {
+ if (contentType != null && contentType.contains("charset=")) {
+ try {
+ return Charset.forName(contentType
+ .substring(contentType.indexOf("charset=") + 8)
+ .trim());
Review Comment:
Valid headers such as `text/plain; charset="ISO-8859-1"` and `text/plain;
charset=ISO-8859-1; format=flowed` pass quotes or trailing parameters to
`Charset.forName()`, causing a UTF-8 fallback that corrupts non-ASCII
diagnostics. Case-insensitive parameter names such as `Charset` are also
missed. Parse individual parameters with case-insensitive names and
quoted-value support, and add tests for these forms.
##########
maven-resolver-transport-apache/src/main/java/org/eclipse/aether/transport/apache/ApacheTransporter.java:
##########
@@ -454,7 +449,7 @@ protected void implPut(PutTask task) throws Exception {
}
try {
execute(request, null, task.getListener());
- } catch (HttpResponseException e) {
+ } catch (HttpTransporterException e) {
Review Comment:
This catch still ends with `throw new
HttpTransporterException(e.getStatusCode())`, so every failed PUT that does not
take the Expect/Continue retry discards the reason phrase and body extract just
collected by the reporter. It also converts an `HttpRFC9457Exception` into a
plain status-only exception now that it is caught here. Please rethrow `e`, as
the updated GET path does, to preserve the diagnostics and subtype.
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/HttpRFC9457Exception.java:
##########
@@ -18,35 +18,21 @@
*/
package org.eclipse.aether.spi.connector.transport.http.RFC9457;
-import java.io.IOException;
-
import org.eclipse.aether.spi.connector.transport.http.HttpTransporter;
+import
org.eclipse.aether.spi.connector.transport.http.HttpTransporterException;
/**
- * Exception thrown by {@link HttpTransporter} in case of errors.
+ * Exception thrown by {@link HttpTransporter} in case of non 2xx responses
carrying a RFC 9457 payload.
*/
-public class HttpRFC9457Exception extends IOException {
- private final int statusCode;
-
- private final String reasonPhrase;
+public class HttpRFC9457Exception extends HttpTransporterException {
private final RFC9457Payload payload;
public HttpRFC9457Exception(int statusCode, String reasonPhrase,
RFC9457Payload payload) {
- super(payload.toString());
- this.statusCode = statusCode;
- this.reasonPhrase = reasonPhrase;
+ super(statusCode, reasonPhrase);
Review Comment:
Changing this to the two-argument superclass constructor removes the RFC
9457 title/detail from the exception message and leaves the inherited
`getDebugMessage()` empty because `bodyExtract` is null. A valid problem
response therefore loses its diagnostic information in both ordinary exception
logging and the new debug-message delegation. Please pass the payload
representation to the body-extract constructor so these details remain
available.
##########
maven-resolver-transport-apache/src/main/java/org/eclipse/aether/transport/apache/ApacheTransporter.java:
##########
@@ -598,12 +593,10 @@ private <T extends HttpUriRequest> void resume(T request,
GetTask task) throws I
}
}
- private void handleStatus(CloseableHttpResponse response) throws Exception
{
+ private void handleStatus(CloseableHttpResponse response) throws
HttpTransporterException {
int status = response.getStatusLine().getStatusCode();
if (status >= 300) {
- ApacheRFC9457Reporter.INSTANCE.generateException(response,
(statusCode, reasonPhrase) -> {
- throw new HttpResponseException(statusCode, reasonPhrase + "
(" + statusCode + ")");
- });
+ ApacheRFC9457Reporter.INSTANCE.generateException(response);
Review Comment:
With WebDAV enabled, an MKCOL error such as 403 or 501 now escapes directory
preparation and prevents PUT from being attempted, instead of being logged and
ignored. `HttpTransporterException` is not an `IOException`, so update both
`mkdirs()` catch clauses (lines 527 and 540) to handle it and preserve
best-effort directory creation.
--
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]