Django

Code

Ticket #2560 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] HttpResponse should support close() for iterators

Reported by: Ivan Sagalaev <Maniac@SoftwareManiacs.Org> Assigned to: adrian
Milestone: Component: Core framework
Version: Keywords:
Cc: Maniac@SoftwareManiacs.Org, mtredinnick Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

WSGI kinda suggests that a server should call 'close()' method of after getting content from a response iterator if it has one. This is very logical since one of the most common examples of an iterator is a file and it really should be closed afterwards. And incidentally 'flup' which is commonly used to run FastCGI server indeed does this.

The problem is that our HttpResponse wraps the actual iterator into a generator (for unicode conversion). And this generator doesn't have 'close()' method and hence the iterator never closed.

I've rewrote this to handle 'close()', patch follows.

Attachments

2560.1.patch (3.8 kB) - added by Ivan Sagalaev <Maniac@SoftwareManiacs.Org> on 08/18/06 08:33:49.
Patch

Change History

08/18/06 08:33:49 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • attachment 2560.1.patch added.

Patch

08/18/06 08:38:34 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

Some comments on the patch:

  • It's somewhat backwards incompatible: before a 'response.iterator' was used to iterator over and now response is an iterator itself. This can be easily fixed by making 'iterator' to return 'self' but I decided to throw it away because it was hardly ever used explicitely and the new approach seems cleaner.
  • The thing that previously was named '_iterator' is now renamed to '_container' which is more pure since an actual iterator is the thing that you get from it be calling 'iter'.

08/18/06 10:16:12 changed by adrian

  • summary changed from HttpResponse should support close() for iterators to [patch] HttpResponse should support close() for iterators.

09/23/06 06:29:59 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

This was fixed in r3791, but the auto-closer didn't kick in.

09/23/06 07:56:26 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • cc changed from Maniac@SoftwareManiacs.Org to Maniac@SoftwareManiacs.Org, mtredinnick.

Sorry, Malcolm, my English is not deep enough to get the second part of what you've said :-). What's an "auto-closer" and what you mean by "didn't kick in"?

09/23/06 07:58:26 changed by mtredinnick

Sorry about that. The "auto-closer" is just my name for whatever it is that automatically reads the svn commit messages and closes the relevant ticket. Sometimes it does not run correctly, even when the commit message is in the right format.

It is completely harmless, don't worry. End result: the bug should be fixed.

09/23/06 08:31:36 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

Got it, thanks :-)


Add/Change #2560 ([patch] HttpResponse should support close() for iterators)




Change Properties
Action