Jump to content
Thijs van Dien

Resetting TIdHTTP before reuse

Recommended Posts

So far, I've been recreating my HTTP client (and SSL handler) for every request, because I'm a little paranoid of leftover state that could affect stability and/or correctness. The price I pay for that, is that I can't benefit from keep-alive. What would I have to do to make sure that no previous request has any influence on the (observable) state of TIdHTTP, except for keeping the connection open? Completely erasing the last response (how?) would be a good start, but perhaps there's more I can do to keep state to a minimum, and always start fresh to the extent possible, while being more efficient at the network level.

Edited by Thijs van Dien

Share this post


Link to post

This doesn't answer your question, but ...

 

... this screams for unit tests like "Ensure requests are still properly going out after the previous server disconnected right in the middle of the transfer, sent garbage or timed out". Not only would you not have to constantly re-recreate clients, you can also sleep easier, knowing (instead of hoping) it works.

Edited by Der schöne Günther

Share this post


Link to post
14 hours ago, Thijs van Dien said:

What would I have to do to make sure that no previous request has any influence on the (observable) state of TIdHTTP, except for keeping the connection open?

TIdHTTP should already be handling that for you.  You don't typically need to do anything extra when sending multiple requests over a single connection.

14 hours ago, Thijs van Dien said:

Completely erasing the last response (how?) would be a good start

Look at TIdHTTP.Request.Clear() and TIdHTTP.Response.Clear()

14 hours ago, Thijs van Dien said:

but perhaps there's more I can do to keep state to a minimum, and always start fresh to the extent possible, while being more efficient at the network level.

Have you actually TRIED to send multiple requests over a single connection and are running in a REAL PROBLEM with it?  If so, what?  Or, are you just SPECULATING?

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×