Hi Oleg,

There is a *getContentLength* method in *AbstractClassicEntityProducer* which
is final and can’t be overwritten (see below) and always return -1 and also
there is no variable which holds content length to overwrite it. If we add
ContentLength header to request builder we get an exception as below. Is
there any other way to generate contentLength.



@Override

public final long getContentLength() {

        return -1;

}


*Exception Thrown*

Caused by: org.apache.hc.core5.http.ProtocolException: Content-Length
header already present

              at
org.apache.hc.core5.http.protocol.RequestContent.process(RequestContent.java:109)

              at
org.apache.hc.core5.http2.protocol.H2RequestContent.process(H2RequestContent.java:76)

              at
org.apache.hc.core5.http.protocol.DefaultHttpProcessor.process(DefaultHttpProcessor.java:107)

              at
org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produceRequest(HttpAsyncMainClientExec.java:148)

              at
org.apache.hc.client5.http.impl.async.LoggingAsyncClientExchangeHandler.produceRequest(LoggingAsyncClientExchangeHandler.java:71)

              at
org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.produceOutput(ClientHttp1StreamHandler.java:183)

              at
org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.execute(ClientHttp1StreamDuplexer.java:326)

              at
org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.processCommands(AbstractHttp1StreamDuplexer.java:239)

              at
org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onOutput(AbstractHttp1StreamDuplexer.java:386)

              at
org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.outputReady(AbstractHttp1IOEventHandler.java:73)

              at
org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.outputReady(ClientHttp1IOEventHandler.java:41)

              at
org.apache.hc.client5.http.impl.async.LoggingIOSession$1.outputReady(LoggingIOSession.java:243)

              at
org.apache.hc.core5.reactor.ssl.SSLIOSession.encryptData(SSLIOSession.java:639)

              at
org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:74)

              at
org.apache.hc.core5.reactor.ssl.SSLIOSession$1.outputReady(SSLIOSession.java:208)

              at
org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:152)

              at
org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)

              at
org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)

              at
org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)

              at
org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:86)

              at
org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)

              ... 1 more



Regards,

Sreenivas
On Sat, Feb 11, 2023, 3:56 PM Oleg Kalnichevski <ol...@apache.org> wrote:

> On Sat, 2023-02-11 at 11:13 +0530, sreenivas somavarapu wrote:
> > Hi Team,
> >
> > We are currently trying to implement Apache HTTP Async Client API for
> > handling HTTP 1.1 and HTTP 2.0 request (Using Servlet request and
> > response). We have implemented classes using
> > *AbstractClassicEntityConsumer*
> > and *AbstractClassicEntityProducer* (as suggested in 5.2 migration
> > guide)
> > which generates request / consumes response into byte array. This
> > results
> > in all request being sent to web server (IIS / Apache) using
> > *chuncked*
> > encoding eventhough we don’t explicitly set it in request headers. Is
> > this
> > expected?
>
> What content length does your entity producer return? If it is -1 the
> protocol handler has no option other than using the chunk transfer
> coding.
>
> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
>
>

Reply via email to