You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Jesus M. Salvo Jr." <je...@migasia.com> on 2003/02/26 08:18:24 UTC

RFE: Method to return an InputStream that includes both HTTP headers and HTTP body

At the moment, the HttpMethod interface has a method 
getResponseBodyAsStream() that returns an InputStream of the HTTP body.
I need a method that returns the _entire_ HTTP response, including the 
HTTP headers and body, in a single InputStream.
The reason for this is that I need to pass the InputStream to JavaMail's 
MimeBodyPart constructor, and MimeBodyPart requires the HTTP headers to 
properly set the MIME headers.

Currently, what I do is:
* call getResponseHeaders()
* For each element in the array of Headers, add them to a StringBuffer
* Add a \r\n to the StringBuffer after all the headers
* Create a ByteArrayInputStream out of the StringBuffer's String.getBytes()
* Create an SequenceInputStream that includes the ByteArrayInputStream 
and the result of getResponseBodyAsStream()

As you can see ... it is quite inefficient.


Regards,

John





Re: RFE: Method to return an InputStream that includes both HTTP headers and HTTP body

Posted by "Jesus M. Salvo Jr." <je...@migasia.com>.
I should qualify that the line containing the HTTP response code _not_ 
be included in the returned InputStream


Ortwin Gl|ck wrote:

> Jesus M. Salvo Jr. wrote:
>
>>
>> At the moment, the HttpMethod interface has a method 
>> getResponseBodyAsStream() that returns an InputStream of the HTTP body.
>> I need a method that returns the _entire_ HTTP response, including 
>> the HTTP headers and body, in a single InputStream.
>> The reason for this is that I need to pass the InputStream to 
>> JavaMail's MimeBodyPart constructor, and MimeBodyPart requires the 
>> HTTP headers to properly set the MIME headers.
>
>
>
> Sounds reasonable. Maybe we can find an easy way to do it. We could 
> add another property "parseHeaders" (default true) to set before you 
> make the request.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>
>


-- 
Jesus M. Salvo Jr.
Mobile Internet Group Pty Ltd
(formerly Softgame International Pty Ltd)
M: +61 409 126699
T: +61 2 94604777
F: +61 2 94603677

PGP Public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0BA5348



Re: RFE: Method to return an InputStream that includes both HTTP headers and HTTP body

Posted by "Jesus M. Salvo Jr." <je...@migasia.com>.
Thanks ... Will it make it to the next alpha ( or beta ) release?


Ortwin Gl|ck wrote:

> Jesus M. Salvo Jr. wrote:
>
>>
>> At the moment, the HttpMethod interface has a method 
>> getResponseBodyAsStream() that returns an InputStream of the HTTP body.
>> I need a method that returns the _entire_ HTTP response, including 
>> the HTTP headers and body, in a single InputStream.
>> The reason for this is that I need to pass the InputStream to 
>> JavaMail's MimeBodyPart constructor, and MimeBodyPart requires the 
>> HTTP headers to properly set the MIME headers.
>
>
>
> Sounds reasonable. Maybe we can find an easy way to do it. We could 
> add another property "parseHeaders" (default true) to set before you 
> make the request.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>
>


-- 
Jesus M. Salvo Jr.
Mobile Internet Group Pty Ltd
(formerly Softgame International Pty Ltd)
M: +61 409 126699
T: +61 2 94604777
F: +61 2 94603677

PGP Public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0BA5348



Re: RFE: Method to return an InputStream that includes both HTTP headers and HTTP body

Posted by Ortwin Glück <or...@nose.ch>.
Jesus M. Salvo Jr. wrote:
> 
> At the moment, the HttpMethod interface has a method 
> getResponseBodyAsStream() that returns an InputStream of the HTTP body.
> I need a method that returns the _entire_ HTTP response, including the 
> HTTP headers and body, in a single InputStream.
> The reason for this is that I need to pass the InputStream to JavaMail's 
> MimeBodyPart constructor, and MimeBodyPart requires the HTTP headers to 
> properly set the MIME headers.


Sounds reasonable. Maybe we can find an easy way to do it. We could add 
another property "parseHeaders" (default true) to set before you make 
the request.


Re: RFE: Method to return an InputStream that includes both HTTP headers and HTTP body

Posted by "Jesus M. Salvo Jr." <je...@migasia.com>.
Definitely ... unless of course setFollowRedirect() is set to false.

Ortwin Gl|ck wrote:

> Jesus M. Salvo Jr. wrote:
>
>>
>> At the moment, the HttpMethod interface has a method 
>> getResponseBodyAsStream() that returns an InputStream of the HTTP body.
>> I need a method that returns the _entire_ HTTP response, including 
>> the HTTP headers and body, in a single InputStream.
>
>
>
> I assume in case of redirection, authentication and the like, you only 
> want the stream from the final request.
>
> Odi
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>
>


-- 
Jesus M. Salvo Jr.
Mobile Internet Group Pty Ltd
(formerly Softgame International Pty Ltd)
M: +61 409 126699
T: +61 2 94604777
F: +61 2 94603677

PGP Public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0BA5348



Re: RFE: Method to return an InputStream that includes both HTTP headers and HTTP body

Posted by Ortwin Glück <or...@nose.ch>.
Jesus M. Salvo Jr. wrote:
> 
> At the moment, the HttpMethod interface has a method 
> getResponseBodyAsStream() that returns an InputStream of the HTTP body.
> I need a method that returns the _entire_ HTTP response, including the 
> HTTP headers and body, in a single InputStream.


I assume in case of redirection, authentication and the like, you only 
want the stream from the final request.

Odi