505
505
if getattr(source, 'swift_conn', None):
506
506
self.close_swift_conn(source)
508
def _make_app_iter(self, node, source, response):
508
def _make_app_iter(self, node, source):
510
510
Returns an iterator over the contents of the source (via its read
511
511
func). There is also quite a bit of cleanup to ensure garbage
512
512
collection works and the underlying socket of the source is closed.
514
:param response: The webob.Response object this iterator should be
515
assigned to via response.app_iter.
516
514
:param source: The httplib.Response object this iterator should read
518
516
:param node: The node the source is reading from, for logging purposes.
522
# Spawn reader to read from the source and place in the queue.
523
# We then drop any reference to the source or node, for garbage
524
# collection purposes.
526
spawn_n(self._make_app_iter_reader, node, source, queue,
527
self.app.logger.thread_locals)
530
chunk = queue.get(timeout=self.app.node_timeout)
531
if isinstance(chunk, bool): # terminator
534
raise Exception(_('Failed to read all data'
539
raise ChunkReadTimeout()
540
except (GeneratorExit, Timeout):
541
self.app.logger.warn(_('Client disconnected on read'))
543
self.app.logger.exception(_('Trying to send to client'))
546
response.app_iter = None
519
# Spawn reader to read from the source and place in the queue.
520
# We then drop any reference to the source or node, for garbage
521
# collection purposes.
523
spawn_n(self._make_app_iter_reader, node, source, queue,
524
self.app.logger.thread_locals)
527
chunk = queue.get(timeout=self.app.node_timeout)
528
if isinstance(chunk, bool): # terminator
531
raise Exception(_('Failed to read all data'
536
raise ChunkReadTimeout()
537
except (GeneratorExit, Timeout):
538
self.app.logger.warn(_('Client disconnected on read'))
540
self.app.logger.exception(_('Trying to send to client'))
548
543
def close_swift_conn(self, src):
656
651
self.close_swift_conn(src)
658
653
res = Response(request=req, conditional_response=True)
659
res.app_iter = self._make_app_iter(node, source, res)
654
res.app_iter = self._make_app_iter(node, source)
660
655
# See NOTE: swift_conn at top of file about this.
661
656
res.swift_conn = source.swift_conn
662
657
update_headers(res, source.getheaders())