elharo commented on a change in pull request #72:
URL: https://github.com/apache/maven-wagon/pull/72#discussion_r467118904
##########
File path:
wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
##########
@@ -152,6 +154,51 @@ 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
Review comment:
is expected to always return --> always returns
##########
File path:
wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
##########
@@ -152,6 +154,51 @@ 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()
+ {
+ String mimeType;
Review comment:
I'd push this into the try block to avoid splitting declaration and
initialization and return from there. The catch block can return the default.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]