0

I am not new to Django (1y work experience) but I have got a strange task that I cannot deal with. So I have to write to write Middleware that will be counting requests, but only those that were not aborted by client (the ones that got fully rendered in browser).

I found out that when client aborts connection, server (Python) throws errno 32 Broken Pipe as it comes from unsuccessful write to socket [I think that connection server-client is TCP there so it is nothing strange].

But the problem is that I cannot find a way to check if browser fully rendered page or to check if that error occurred (of course that error can have another origin but it would be a good start).

Ohhh and I don't want to use JS (with JS it is a piece of cake) but I can use HTML5 (if it can help...)

Piotr Jaszkowski
  • 1,150
  • 9
  • 12
  • You could try putting a web bug (1px x 1px) image at the very bottom of the page. Maybe load it via a `view()` (as opposed to from your static server). There's no guarantee that the page is 100% rendered at that point, but it should be mostly done. And since you mention no JS for the check, then I assume you are not using any JS for the page itself. – Peter Rowell May 13 '12 at 23:25
  • Yes, I was thinking about that (I have already done smth like this) but I'm not sure if this is what my 'client' wants. He said middleware... – Piotr Jaszkowski May 14 '12 at 07:45
  • It sounds like your client may be doing what I call "over speccing": over specifying both the desired end result *and* how to achieve it. Assuming this is not a homework assignment, it may be a good time to sit down with your client, clarify the *desired end result*, and then assert some technical independence on how to achieve it. – Peter Rowell May 14 '12 at 15:30

1 Answers1

0

I may have found the answer to your question, that is execute some code when the HTTPResponse has been sent. You can then increment what you want after the page has been fully sent to the client.

The example subclasses HttpResponse and returns an instance of the derived class explicitly in a view. If you have many views you don't want to override, maybe you could try this piece of code under your subclass definition

HttpResponse.__bases__ += (FullLoggingHttpResponse,)
Community
  • 1
  • 1
Steve K
  • 10,879
  • 4
  • 39
  • 39
  • It looks promising, I'll check it later. If it works I'll accept. About the problem you stated I think that decorators would do the work. – Piotr Jaszkowski May 14 '12 at 07:41