Question:

I am having a problem identifying read timeouts from sites.

I set ConnectTimeout and ReadTimeout properties of the HTTP object.

When the site fails to respond within ReadTimeout, the following happens:

  • PText still returns 0
  • PText returns a response object
  • Reading of StatusCode and StatusText properties of the response object is successful
  • Reading of BodyStr property of the response object is successful
  • StatusCode is 0
  • StatusText is empty
  • BodyStr is null

What would be the proper way of identifying ReadTimeout (and potentially ConnectTimeout) ?

Answer:

  • The ConnectTimeout property is the number of seconds to wait for the web server to accept the connection for the HTTP request.  If no connection to the server could be established after waiting for this number of seconds, the method will return a null pointer (0) instead of an HttpResponse object, and the http.ConnectFailReason property will be set to an integer value indicating the reason.
  • Once the TCP connection is made, the ReadTimeout applies to receiving responses from the server.  This includes the TLS handshake that happens automatically when connecting via TLS (i.e. https).   The ReadTimeout is the max time to wait for more incoming data.  It is NOT the max time to wait for an entire response.  Let’s say the response is 20 gigabytes, and the ReadTimeout is 60. It will take a long time to receive 20 gigabytes; much longer than 60 seconds.  However, if the incoming data pauses for more than the ReadTimeout value, then Chilkat will return with a failure.
  • If a method returns 0/null instead of an HttpResponse object, then it means no response was received.  It may be that the failure was during the sending of the request.  Or it may be that the request was sent, but the server did not respond, or maybe the server disconnected for some reason (perhaps it did not like the content of the request).
  • I don’t think it’s possible for an HttpResponse object to be returned with a StatusCode = 0.   The first thing sent in an HTTP response is the status code, so if any response is received, it should at least have a status code.   (If an application instantiates a new instance of HttpResponse, then the StatusCode would have an initial value of 0.)
  • The StatusText, like the StatusCode, shouldn’t be empty if any response was received.
  • The HttpResponse.BodyStr should never be null because it’s a property.  A string *property* (as opposed to a method that returns a string) can never be null.  It can be empty, and an HTTP response that contains no body can certainly happen.  For example, it is typical for 204 status code responses to contain no body.