You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Slikey <gi...@git.apache.org> on 2015/10/12 02:08:55 UTC

[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

GitHub user Slikey opened a pull request:

    https://github.com/apache/httpclient/pull/36

    Allow usage of MultipartFormEntity in HttpAsyncClient.

    There currently is only a workaround for the usage of MultipartFormEntity which requires sending the binary data of the MultipartFormEntity to a NByteArrayEntity. Actually I couldn't get this workaround working and it appears to not capture all part of the purpose of MultipartFormEntity.
    See: http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/201311.mbox/%3C13034392.132.1384195516775.JavaMail.Hal@Harold-Rosenbergs-MacBook-Pro.local%3E
    
    This fix allows the usage of the MultipartFormEntity in the HttpAsyncClient because it calls #getContent() instead of #writeTo().
    
    See people who have a similar problem:
    http://stackoverflow.com/questions/4720077/how-can-i-see-the-content-of-a-multipartform-request
    https://github.com/Mashape/unirest-java/issues/31
    
    Something I want to point out is this quote: "That's the problem with trying to mix an asynchronous transport with an inherently blocking content producer. MultipartFormEntity can only produce its content using #writeTo method and cannot be used asynchronously. You basically have two options. (1) Write out entity content to ByteArrayOutputStream (or similar) and then create NByteArrayEntity using the resultant byte array. (2) Create multipart entity implementation that can produce its content asynchronously. " - Source: http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/201311.mbox/%3C13034392.132.1384195516775.JavaMail.Hal@Harold-Rosenbergs-MacBook-Pro.local%3E
    
    I'd like to get some discussion going on this approach and end up having a solution to this problem because I had to recreate part of the HttpMime in my project to support MultipartFormEntity in my HttpAsyncClient.
    
    Thank you for reading!

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/Slikey/httpclient trunk

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/httpclient/pull/36.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #36
    
----
commit 7605310c2ddde28766b644d1a4a36a82bff041c2
Author: Slikey <tr...@kevin-carstens.de>
Date:   2015-10-12T00:01:00Z

    Allow usage of MultipartFormEntity in HttpAsyncClient.
    
    There currently is only a workaround for the usage of MultipartFormEntity which requires sending the binary data of the MultipartFormEntity to a NByteArrayEntity. Actually I couldn't get this workaround working and it appears to not capture all part of the purpose of MultipartFormEntity.
    See: http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/201311.mbox/%3C13034392.132.1384195516775.JavaMail.Hal@Harold-Rosenbergs-MacBook-Pro.local%3E
    
    This fix allows the usage of the MultipartFormEntity in the HttpAsyncClient because it calls #getContent() instead of #writeTo().
    
    See people who have a similar problem:
    http://stackoverflow.com/questions/4720077/how-can-i-see-the-content-of-a-multipartform-request
    https://github.com/Mashape/unirest-java/issues/31
    
    Something I want to point out is this quote: "That's the problem with trying to mix an asynchronous transport with an inherently blocking content producer. MultipartFormEntity can only produce its content using #writeTo method and cannot be used asynchronously. You basically have two options. (1) Write out entity content to ByteArrayOutputStream (or similar) and then create NByteArrayEntity using the resultant byte array. (2) Create multipart entity implementation that can produce its content asynchronously. " - Source: http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/201311.mbox/%3C13034392.132.1384195516775.JavaMail.Hal@Harold-Rosenbergs-MacBook-Pro.local%3E
    
    I'd like to get some discussion going on this approach and end up having a solution to this problem because I had to recreate part of the HttpMime in my project to support MultipartFormEntity in my HttpAsyncClient.
    
    Thank you for reading!

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by ok2c <gi...@git.apache.org>.
Github user ok2c commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-207750257
  
    You are welcome to contribute improved javadocs / documentation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by ok2c <gi...@git.apache.org>.
Github user ok2c commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-147699032
  
    I would add one last thing here. I think it would be reasonable to not attempt to buffer the entity content if it is too large or its length is unknown. I would put a cap on the content length to 20K or something like that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by ok2c <gi...@git.apache.org>.
Github user ok2c commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-147330073
  
    If you want this patch committed to the stable 4.5 branch could you please make your code Java 1.6 compatible and also avoid using * imports?
    
    Any development related discussions should be held at dev@hc.apache.org 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by ok2c <gi...@git.apache.org>.
Github user ok2c commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-147998982
  
    One can always use BufferedHttpEntity to explicitly buffer entities of arbitrary length or explicitly write multipart content out to a byte[]. What I avoid is causing substantial memory allocation for unsuspected clueless users.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by ok2c <gi...@git.apache.org>.
Github user ok2c commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-149882164
  
    Committed to SVN trunk and 4.5.x branch with some modifications
    http://svn.apache.org/viewvc?rev=1709814&view=rev


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by jacohend <gi...@git.apache.org>.
Github user jacohend commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-207515667
  
    The 20k restriction is much *more* of a problem for unsuspecting users trying to use a library that is literally intended to, among other functions, upload binary data. At no point should my network library be making extremely low content length restrictions for me. If you want users to be aware that the library makes a full additional copy and to use BufferedHttpEntity in the case of large binary files, then I would suggest putting it in the documentation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by Slikey <gi...@git.apache.org>.
Github user Slikey commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-147745437
  
    Hello, I don't want to disable this feature for requests above 20K, because the content can easily get higher than 20K due to the binary data which is carried inside. I'd rather propose that I instantiate the InputStream and fill it from a different Thread if blocking is a concern.
    Are there any Utilities in this repository for that? Since the code has to be 1.6 compatible, the PipedInputStream is not available for my use.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] httpclient pull request: Allow usage of MultipartFormEntity in Htt...

Posted by Slikey <gi...@git.apache.org>.
Github user Slikey commented on the pull request:

    https://github.com/apache/httpclient/pull/36#issuecomment-147454374
  
    Thank you for the response. I've change the code to compile against 1.6 and removed the * imports.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org