hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Lochart" <dloch...@gmail.com>
Subject Re: HttpEntity and getContent()
Date Thu, 24 Aug 2006 15:30:35 GMT
>
>
> Doug,
> Please consider a situation where the server has to send back to the
> client several megabyte of content in the response body. Most likely one
> would not want to have all that content buffered in memory. Such
> architecture simply will not perform and scale.
>
> Therefore HttpCore uses an abstract HttpEntity interface to represent an
> entity. Those entities can be static, whose content is fully contained
> in the entity itself, or "streaming", that is producing content on fly.
>
> One can (and should) assemble a response object that contains only
> response status line, headers and a reference to an HttpEntity that will
> be used to produce the desired content while the response is being
> streamed out to the client.
>
> Hope that makes things somewhat clearer.
>
> Oleg
>

Yes it does.  This makes me think that the suggestion Roland gave about
wrapping the InputStream  with a stream that modifies on the fly is probably
my best choice.   Something like :
HttpEntity entity = responseFromWebServer.getEntity();
HttpEntityFilterDecorator filtered = new HttpEntityFilterDecorator( entity
);
responseToClient.setEntity( filteredEntity );

with something like this ...

public class HttpEntityFilterDecorator implements HttpEntity {
    private final HttpEntity _entity;

    public HttpEntityFilterDecorator(HttpEntity entity) {
       ...
       _entity = entity;
    }

    // other interface  methods are pass through

    public InputStream getContent() throws IOException,
IllegalStateException {
       BufferedContentFilteringInputStream bcfis = new
BufferedContentFilteringInputStream( super.getContent() );
       return bcfis;
    }
}

Suggestions.  I know I'll have to determine content type etc before I start
filtering.  I don't intend on filtering images =)

Doug

-- 
What profits a man if he gains the whole world yet loses his soul?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message