-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MNG-6975] Wagon-HTTP, set content-type when determinable from file extension #72
base: master
Are you sure you want to change the base?
Conversation
…eader if that is not empty
wagon-providers/pom.xml
Outdated
<profile> | ||
<id>jdk11</id> | ||
<activation> | ||
<jdk>[1.11,)</jdk> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really 1.11? If yes, then this is a bug in Maven.
* <b>disabled by default</b> | ||
* This flag is only effective when uploading from a File, not directly from a Stream. | ||
*/ | ||
private static final boolean SET_CONTENT_TYPE_FROM_FILE_EXTENSION = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether this should be a per-server config rather than global. In general, sys props are either globally or for a technical reason. WDYT?
regarding: "Is it really 1.11? If yes, then this is a bug in Maven."
Just to be sure I tested it with "1.11" and with "11" and they both worked.
I then tried with "12" (I'm running JDK 11) and it failed with the expected
missing package. I think it works either way.
regarding: "per-server config rather than global."
I agree, is there an example you can point me to that I can start from?
On Thu, Aug 6, 2020 at 11:17 AM Michael Osipov ***@***.***> wrote:
*This email was sent from an external source so please treat with caution.*
------------------------------
***@***.**** commented on this pull request.
------------------------------
In wagon-providers/pom.xml
<#72 (comment)>
:
> @@ -78,4 +78,20 @@ under the License.
<scope>test</scope>
</dependency>
</dependencies>
+
+ <profiles>
+ <profile>
+ <id>jdk11</id>
+ <activation>
+ <jdk>[1.11,)</jdk>
Is it really 1.11? If yes, then this is a bug in Maven.
------------------------------
In
wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
<#72 (comment)>
:
> @@ -279,6 +296,13 @@ public boolean isStreaming()
private static final boolean SSL_ALLOW_ALL =
Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.allowall", "false" ) );
+ /**
+ * If enabled, then the content-type HTTP header will be set using the file extension to determine the type,
+ * <b>disabled by default</b>
+ * This flag is only effective when uploading from a File, not directly from a Stream.
+ */
+ private static final boolean SET_CONTENT_TYPE_FROM_FILE_EXTENSION =
I wonder whether this should be a per-server config rather than global. In
general, sys props are either globally or for a technical reason. WDYT?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#72 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMYZJ7EINPE3U7SSVUIEOODR7LCITANCNFSM4PWVNA4A>
.
About Ascential plc: Ascential (LSE:ASCL.L) is a specialist information, data and analytics company that helps the world’s most ambitious businesses win in the digital economy. Our information, insights, connections, data and digital tools solve customer problems in three disciplines:
Product Design via global trend forecasting service WGSN;
Marketing via global benchmark for creative excellence and effectiveness Cannes Lions and WARC and strategic advisory firm MediaLink; and
Sales via ecommerce-driven data, insights and advisory service Edge by Ascential, leading managed services provider for Amazon Flywheel Digital, the world's premier payments and Fin Tech congress Money20/20, global retail industry summit World Retail Congress and retail news outlet Retail Week.
Ascential also powers political, construction and environmental intelligence brands DeHavilland, Glenigan and Groundsure.
The information in or attached to this email is confidential and may be legally privileged. If you are not the intended recipient of this message, any use, disclosure, copying, distribution or any action taken in reliance on it is prohibited and may be unlawful.
If you have received this message in error, please notify the sender immediately by return email and delete this message and any copies from your computer and network. Ascential does not warrant that this email and any attachments are free from viruses and accepts no liability for any loss resulting from infected email transmissions.
Ascential reserves the right to monitor all email through its networks. Any view expressed may be those of the originator and not necessarily of Ascential plc.
Please be advised all phone calls may be recorded for training and quality purposes and by accepting and/or making calls to us you acknowledge and agree to calls being recorded.
Ascential plc, number 9934451 (England and Wales). Registered Office: The Prow, 1 Wilder Walk, London W1B 5AP.
|
...on-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Outdated
Show resolved
Hide resolved
Yeah, but why it did? I think that 1.11 works only because when
normalized string is tested against range I am pretty sure it shall be |
Regarding the version 1.11 vs 11: in following up on the suggestion by @elharo to use URLConnection.guess... the need for javax.activation has been negated. Update to the PR is coming soon. |
… File extension to mime type map.
Updated to use URLConnection.guess***, which also allows this to work with streaming. Added a second property to control behavior when an error in content identification occurs. Default to creating content-type and not failing if determining content-type fails. Thanks to @elharo for the suggestion, this is better than before. |
...on-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Outdated
Show resolved
Hide resolved
The stream guessing is almost pointless, look at its code: https://github.com/battleblow/openjdk-jdk8u/blob/bsd-port/jdk/src/share/classes/java/net/URLConnection.java Path based approach looks better:
You can even supply a custom file with |
...on-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Outdated
Show resolved
Hide resolved
* or the stream header to determine the type, <b>disabled by default</b> | ||
*/ | ||
private static final boolean AUTOSET_CONTENT_TYPE = | ||
Boolean.valueOf( System.getProperty( "maven.wagon.http.autocontenttype", "true" ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand it's pattern copied from existing code - but why in new code not use parseBoolean
instead of valueOf
and skip unboxing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that in OSS contributions, at least others I've made, consistency is valued highly. No other reason and, FWIW and IMHO, unboxing/autoboxing should be banished from decent society.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of Maven code is 10+ years old and dates back to Java 1.4 and earlier. It can be quite crufty, and consistency alone is not a string argument in this context. The things we really care about are written down in the docs. Everything else should assume best current practices for Java 1.7.
@chrisbeckey What is your stance on my previous comment? |
@michael-o I'm not sure I understand the comment. "guessContentTypeFromStream" is invoked if the source is an InputStream, not when reading from a File, there is no extension available to determine the content from. |
@michael-o Is there a better way to determine content from a Stream (not from a file name, which is handled separately)? |
Boolean.valueOf( System.getProperty( "maven.wagon.http.autocontenttype", "true" ) ); | ||
|
||
/** | ||
* If enabled, then an when determining the content type will result in a fatal exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an --> an error
will result --> results
...on-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Outdated
Show resolved
Hide resolved
@chrisbeckey Not with external libraries. |
@michael-o assuming you meant "Not WITHOUT external libraries." ? |
…l exception behavior
...on-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Outdated
Show resolved
Hide resolved
...on-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Show resolved
Hide resolved
? URLConnection.guessContentTypeFromName( this.source.getName() ) | ||
: this.stream != null | ||
? URLConnection.guessContentTypeFromStream( this.stream ) | ||
: DEFAULT_CONTENT_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider this like to be redundant: RFC 7231, section 3.1.1.5:
If a Content-Type header field is not present, the recipient
MAY either assume a media type of "application/octet-stream"
([RFC2046], Section 4.5.1) or examine the data to determine its type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this is redundant, and I think most of the interest in this change is from people using client software that's bespoke, naive, or maybe completely ignorant of the RFC.
That said, I'd recommend doing it anyway. It's becoming apparent to me that there is a lot of client software out there that doesn't know/implement RFC 7231, section 3.1.1.5. It's perfectly correct to not do this, but it's also a good way to keep getting asked the question by newbies (like I was). Unless you really want to keep educating people about it, I'd recommend just returning the default that the caller should assume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced that it is the entity's task to set the content type. It is the caller's task The HttpEntity
is solely designed to carry data w/o any logic at best.
I will pick this up by the end of the week. |
There are still statements which have not been responded to. Until then this PR will remain open. |
Still interested in completing this? |
As a note: My (minor) issue could have benefited from this: https://issues.apache.org/jira/browse/MDEPLOY-289 The summary is our enterprise (amazon) used custom maven repository proxies. It would be nice to not default/guess content type when missing. |
Closed by accident |
I am still interested in seen this land. In our case the WAF complained about the absence of a
P.S. Maybe the description of this PR should mention that it'll fix https://issues.apache.org/jira/browse/WAGON-599. |
This is a bug in your WAF: https://www.rfc-editor.org/rfc/rfc9110.html#name-content-type |
I didn't claim there be anything "wrong" with the request. Of course we can adjust the security profile in the WAF such that it allows PUT requests without |
Set the HTTP content-type header,
using the file extension to determine value, when uploading a file.
using the header when uploading a Stream