Copilot commented on code in PR #72:
URL: https://github.com/apache/maven-wagon/pull/72#discussion_r3214977777
##########
wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java:
##########
@@ -152,6 +154,49 @@ private WagonHttpEntity( final InputStream stream, final
Resource resource, fina
this.length = resource == null ? -1 : resource.getContentLength();
this.wagon = wagon;
+
+ // if the autoset content flag is SET and the content type is blank
+ // then try to determine what the content type is and set it
+ if ( AUTOSET_CONTENT_TYPE && getContentType() == null )
+ {
+ setContentType( determineContentType() );
+ }
+ }
+
+ /**
+ * Best effort to determine the content type.
+ *
+ * if the content is coming from a file and the content type is
determinable from the file extension
+ * or
+ * if the content is coming from a stream and the content type is
determinable from the stream
+ * (guessContentTypeFromStream will return null if the InputStream
does not support mark())
+ * then determine and return the content type
+ * if the content type is not determinable then return
"application/octet-stream"
+ *
+ * NOTE: this method is expected to always return a non-empty String
+ */
+ private String determineContentType()
+ {
+ try
+ {
+ String mimeType = this.source != null
+ ? URLConnection.guessContentTypeFromName(
this.source.getName() )
+ : this.stream != null
+ ? URLConnection.guessContentTypeFromStream(
this.stream )
+ : DEFAULT_CONTENT_TYPE;
+
Review Comment:
MIME type detection for file uploads uses the local `source.getName()`.
Since callers can upload a file under a different remote `resource.getName()`
(e.g., temporary file without extension), this can produce an incorrect
`Content-Type` header. Prefer determining the type from the
destination/resource name (fall back to `source.getName()` only if needed).
##########
wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java:
##########
@@ -122,6 +123,7 @@ public abstract class AbstractHttpClientWagon
final class WagonHttpEntity
extends AbstractHttpEntity
{
+ public static final String DEFAULT_CONTENT_TYPE =
"application/octet-stream";
Review Comment:
`DEFAULT_CONTENT_TYPE` does not appear to be referenced outside
`WagonHttpEntity`; making it `public` expands the surface area unnecessarily.
Consider reducing visibility (e.g., `private static final`) to avoid it
becoming an accidental API within the package.
--
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]