Ejemplo n.º 1
0
	def done (self):
		"finalize this transaction - send output to the http channel"

		# ----------------------------------------
		# persistent connection management
		# ----------------------------------------

		#  --- BUCKLE UP! ----

		connection = string.lower (get_header (CONNECTION, self.header))

		close_it = 0
		wrap_in_chunking = 0

		if self.version == '1.0':
			if connection == 'keep-alive':
				if not self.has_key ('Content-Length'):
					close_it = 1
				else:
					self['Connection'] = 'Keep-Alive'
			else:
				close_it = 1
		elif self.version == '1.1':
			if connection == 'close':
				close_it = 1
			elif not self.has_key ('Content-Length'):
				if self.has_key ('Transfer-Encoding'):
					if not self['Transfer-Encoding'] == 'chunked':
						close_it = 1
				elif self.use_chunked:
					self['Transfer-Encoding'] = 'chunked'
					wrap_in_chunking = 1
				else:
					close_it = 1
		elif self.version is None:
			# Although we don't *really* support http/0.9 (because we'd have to
			# use \r\n as a terminator, and it would just yuck up a lot of stuff)
			# it's very common for developers to not want to type a version number
			# when using telnet to debug a server.
			close_it = 1
					
		outgoing_header = producers.simple_producer (self.build_reply_header())

		if close_it:
			self['Connection'] = 'close'

		if wrap_in_chunking:
			outgoing_producer = producers.chunked_producer (
				producers.composite_producer (self.outgoing)
				)
			# prepend the header
			outgoing_producer = producers.composite_producer (
				fifo([outgoing_header, outgoing_producer])
				)
		else:
			# prepend the header
			self.outgoing.push_front (outgoing_header)
			outgoing_producer = producers.composite_producer (self.outgoing)

		# apply a few final transformations to the output
		self.channel.push_with_producer (
			# globbing gives us large packets
			producers.globbing_producer (
				# hooking lets us log the number of bytes sent
				producers.hooked_producer (
					outgoing_producer,
					self.log
					)
				)
			)

		self.channel.current_request = None

		if close_it:
			self.channel.close_when_done()
Ejemplo n.º 2
0
    def done (self):
        "finalize this transaction - send output to the http channel"

        # ----------------------------------------
        # persistent connection management
        # ----------------------------------------

        #  --- BUCKLE UP! ----

        connection = string.lower (get_header (CONNECTION, self.header))

        close_it = 0
        wrap_in_chunking = 0

        if self.version == '1.0':
            if connection == 'keep-alive':
                if not self.has_key ('Content-Length'):
                    close_it = 1
                else:
                    self['Connection'] = 'Keep-Alive'
            else:
                close_it = 1
        elif self.version == '1.1':
            if connection == 'close':
                close_it = 1
            elif not self.has_key ('Content-Length'):
                if self.has_key ('Transfer-Encoding'):
                    if not self['Transfer-Encoding'] == 'chunked':
                        close_it = 1
                elif self.use_chunked:
                    self['Transfer-Encoding'] = 'chunked'
                    wrap_in_chunking = 1
                else:
                    close_it = 1
        elif self.version is None:
            # Although we don't *really* support http/0.9 (because we'd have to
            # use \r\n as a terminator, and it would just yuck up a lot of stuff)
            # it's very common for developers to not want to type a version number
            # when using telnet to debug a server.
            close_it = 1

        outgoing_header = producers.simple_producer(self.get_reply_header_text())

        if close_it:
            self['Connection'] = 'close'

        if wrap_in_chunking:
            outgoing_producer = producers.chunked_producer (
                    producers.composite_producer (self.outgoing)
                    )
            # prepend the header
            outgoing_producer = producers.composite_producer(
                [outgoing_header, outgoing_producer]
                )
        else:
            # prepend the header
            self.outgoing.insert(0, outgoing_header)
            outgoing_producer = producers.composite_producer (self.outgoing)

        # apply a few final transformations to the output
        self.channel.push_with_producer (
                # globbing gives us large packets
                producers.globbing_producer (
                        # hooking lets us log the number of bytes sent
                        producers.hooked_producer (
                                outgoing_producer,
                                self.log
                                )
                        )
                )

        self.channel.current_request = None

        if close_it:
            self.channel.close_when_done()