'By default the timeout value at OpenerSettings is set to 0, which means
that w3af needs to auto-adjust it based on the HTTP request/response
RTT. This method takes care of the process of adjusting the socket
timeout.
The objective of auto-adjusting the timeout is to "fail fast" on
requests which are going to fail anyways. In previous versions of w3af
the default timeout was 15 seconds, which made the scanner delay A LOT
on URLs which (for some reason like heavy processing on the server side)
failed anyways.
We calculate and adjust the new timeout every 50 successful requests.
The timeout is calculated using average(RTT) * TIMEOUT_MULT_CONST , then
for example if the average RTT is 0.3 seconds and the TIMEOUT_MULT_CONST
is at 6.5 we end up with a real socket timeout of 1.95
The TIMEOUT_MULT_CONST might be lowered by advanced users to achieve
faster scans in scenarios where timeouts are slowing down the scans.
TODO
After implementing this feature I noticed that there is a big mismatch
between what I wanted to achieve and what\'s actually happening in real
life. When I set the timeout it is used for creating new
HTTPConnections. Those connections are use to send ~100 requests each.
If w3af adjusts the timeout every 25 requests, it doesn\'t matter much
since the change will only take effect when a new HTTPConnection is
created in the pool.
I\'m not sure how to fix the issue above, so I\'m documenting some things
that will NOT work just in case:
* Increasing/decreasing the TIMEOUT_ADJUST_LIMIT
* Setting timeouts for specific HTTP Requests using the timeout arg
* Forcing HTTPConnections to be closed in the pool each time the
timeout is updated could work, but that will slow down the scan
and make the keep alive handler less efficient
:see: https://github.com/andresriancho/w3af/issues/8698
:return: None, we adjust the value at the "settings" attribute'

def _auto_adjust_timeout(self, request):

    if (not self._should_auto_adjust_now()):
        return
    host = request.get_host()
    (average_rtt, num_samples) = self.get_average_rtt(TIMEOUT_ADJUST_LIMIT, host)
    if (num_samples < (TIMEOUT_ADJUST_LIMIT / 2)):
        msg = 'Not    enough    samples    collected    (%s)    to    adjust    timeout.    Keeping    the    current    value    of    %s    seconds'
        om.out.debug((msg % (num_samples, self.get_timeout(host))))
    else:
        timeout = (average_rtt * TIMEOUT_MULT_CONST)
        timeout = max(timeout, TIMEOUT_MIN)
        self.set_timeout(timeout, host)
