-
Notifications
You must be signed in to change notification settings - Fork 100
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
Open
chrisbeckey
wants to merge
10
commits into
apache:master
Choose a base branch
from
chrisbeckey:MNG-6975
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3ae49fc
determine the content type from file extension and set content-type h…
002b8be
added system property to control determination of content type from f…
eb70394
correct checkstyle error
e71d0d3
fixed comment on system property (flag)
d456301
add conditional on existing content-type and handle JDK11 activation …
51a6fd7
removed dependency on javax.activation, use URLConnection rather than…
928a393
added a comment to indicate behavior of URLConnection.guessContentTyp…
4ea523b
correct comment, autocontenttype is on by default
c9761c1
if autoset is on SET then always set the content-type, remove optiona…
3643d92
moved declaration
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ | |
import org.apache.maven.wagon.resource.Resource; | ||
import org.codehaus.plexus.util.StringUtils; | ||
|
||
import javax.activation.MimetypesFileTypeMap; | ||
chrisbeckey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import javax.net.ssl.HttpsURLConnection; | ||
import javax.net.ssl.SSLContext; | ||
import java.io.Closeable; | ||
|
@@ -119,6 +120,8 @@ | |
public abstract class AbstractHttpClientWagon | ||
extends StreamWagon | ||
{ | ||
private static final MimetypesFileTypeMap FILE_TYPE_MAP = new MimetypesFileTypeMap(); | ||
|
||
final class WagonHttpEntity | ||
extends AbstractHttpEntity | ||
{ | ||
|
@@ -142,6 +145,19 @@ private WagonHttpEntity( final InputStream stream, final Resource resource, fina | |
{ | ||
this.source = source; | ||
this.repeatable = true; | ||
// if the content-type has not been set then | ||
// if the option flag is TRUE and the content type is determinable from the file extension | ||
// then set it from the file extension | ||
if ( getContentType() == null ) | ||
{ | ||
final String mimeType = SET_CONTENT_TYPE_FROM_FILE_EXTENSION | ||
? FILE_TYPE_MAP.getContentType( source ) | ||
: null; | ||
if ( mimeType != null && !mimeType.isEmpty() ) | ||
{ | ||
setContentType( mimeType ); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
|
@@ -152,6 +168,7 @@ private WagonHttpEntity( final InputStream stream, final Resource resource, fina | |
this.length = resource == null ? -1 : resource.getContentLength(); | ||
|
||
this.wagon = wagon; | ||
|
||
} | ||
|
||
public Resource getResource() | ||
|
@@ -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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
Boolean.valueOf( System.getProperty( "maven.wagon.http.file.autocontenttype", "false" ) ); | ||
|
||
/** | ||
* Maximum concurrent connections per distinct route. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.