mozilla-services/loads — pull request #260 by jgsbennett (2014-04-29 12:33:06+00:00)
Title: Fix handling of redirects. Previously, if a url caused a redirect, the r...

...edirected url and time would be recorded twice(or more times for more redirects) in the results, as opposed to correct info for each individual request being recorded before the subsequent redirect.

I'll confess that I haven't done extensive testing of this, but it fixes the problem I was seeing for me. (In particular, I haven't run any of the tests included in the module, so apologies if this is just plain broken!).

The problem this addresses:
If the page that Session.send() is trying to access is a url that causes a redirect, from url a to url b say, then a hit is recorded for url b twice, with the start/elapsed time both being for url b, since the res.started /res.elapsed and res.url properties are all overwritten. This means that loads does not record any info for url a(although the total number of hits it records is correct, assuming that you are in fact interested in the redirect hits).
In practice, if there were several redirects, this means you would only record the last request, and that it would be recorded once for each request in the redirect chain that led to it.

The suggested fix below makes resolve_redirects() record information for the hit before attempting the redirected request. The final non-redirected request is still recorded in 'send'.

Notes:
- requests module has an is_redirect property being added to Response, which is not in the released 2.2.1 requests module. Depending on the next loads release date, it will probably be desirable to change the first line in resolve_redirects() to make use of this.
- I've made an assumption that the redirected hits are interesting enough to fix logging them properly. I could imagine that users of the module might want to know the total elapsed time from first url until the end of any redirects for the first link? (i.e: Still allow redirects, but don't count it as a separate hit), although personally I'm not all that fussed.