Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 990D3200C4B for ; Mon, 20 Mar 2017 14:48:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 97B33160B76; Mon, 20 Mar 2017 13:48:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EB4A8160B81 for ; Mon, 20 Mar 2017 14:48:48 +0100 (CET) Received: (qmail 35948 invoked by uid 500); 20 Mar 2017 13:48:47 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 35608 invoked by uid 99); 20 Mar 2017 13:48:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Mar 2017 13:48:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B623B18F186 for ; Mon, 20 Mar 2017 13:48:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.451 X-Spam-Level: * X-Spam-Status: No, score=1.451 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id KHRL-q2xMCdV for ; Mon, 20 Mar 2017 13:48:45 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 2B97861E28 for ; Mon, 20 Mar 2017 13:48:44 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A99DAE0BC8 for ; Mon, 20 Mar 2017 13:48:42 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id B73CC254D9 for ; Mon, 20 Mar 2017 13:48:41 +0000 (UTC) Date: Mon, 20 Mar 2017 13:48:41 +0000 (UTC) From: "Oleg Kalnichevski (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (HTTPCLIENT-1832) Provide InputStreamBody with contentLength if known MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 20 Mar 2017 13:48:49 -0000 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1832?page=3Dcom.atl= assian.jira.plugin.system.issuetabpanels:all-tabpanel ] Oleg Kalnichevski resolved HTTPCLIENT-1832. ------------------------------------------- Resolution: Fixed Fix Version/s: 5.0 Alpha2 4.6 Alpha1 Implemented in SVN trunk and 4.6.x branch.=20 Please review and close. Oleg > Provide InputStreamBody with contentLength if known > --------------------------------------------------- > > Key: HTTPCLIENT-1832 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-183= 2 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) > Affects Versions: 4.5.3 > Environment: windows 10 64 bit, oracle jdk 1.8.0_112 64bit > Reporter: Marcel Thannh=C3=A4user > Fix For: 4.6 Alpha1, 5.0 Alpha2 > > > When building a multipart request that consists of at least one body wher= e the contentLength is -1 in AbstractMultipartForm#getTotalLength -1 is ret= urned, resulting in a missing Content-Length header in the request. This be= haviour is correct.=20 > But in some cases you know the contentLength of a body part even though i= t might be streamed.=20 > To implement this I subclassed org.apache.http.entity.mime.content.InputS= treamBody=20 > =09public class ContentLengthInputStreamBody extends InputStreamBody { > =09=09private final long contentLength; > =09=09 > =09=09public ContentLengthInputStreamBody(InputStream in, ContentType con= tentType, String filename, long contentLength ) { > =09=09=09super(in, contentType, filename); > =09=09=09this.contentLength =3D contentLength; > =09=09} > =09=09@Override > =09=09public long getContentLength() { > =09=09=09return this.contentLength; > =09=09} > =09=09 > =09} > I also needed to do this because a foreign HTTP Server, which is not unde= r my control, refused to handle my request when the Content-Length header w= as not set. > This might not be a common issue nor is it hard to solve, but you might t= hink of adding this functionality to InputStreamBody itself. -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org