def status(self):
     # Thanks to [email protected] (Mike Meyer)
     r = [
         producers.simple_producer('<li>Authorization Extension : '
                                   '<b>Unauthorized requests:</b> %s<ul>' %
                                   self.fail_count)
     ]
     if hasattr(self.handler, 'status'):
         r.append(self.handler.status())
     r.append(producers.simple_producer('</ul>'))
     return producers.composite_producer(r)
 def status(self):
     # Thanks to [email protected] (Mike Meyer)
     r = [
         producers.simple_producer(
             "<li>Authorization Extension : " "<b>Unauthorized requests:</b> %s<ul>" % self.fail_count
         )
     ]
     if hasattr(self.handler, "status"):
         r.append(self.handler.status())
     r.append(producers.simple_producer("</ul>"))
     return producers.composite_producer(r)
Exemple #3
0
    def status(self):
        from supervisor.medusa.util import english_bytes

        def nice_bytes(n):
            return ''.join(english_bytes(n))

        handler_stats = [_f for _f in map(maybe_status, self.handlers) if _f]

        if self.total_clients:
            ratio = self.total_requests.as_long() / float(
                self.total_clients.as_long())
        else:
            ratio = 0.0

        return producers.composite_producer([
            producers.lines_producer([
                '<h2>%s</h2>' % self.SERVER_IDENT,
                '<br>Listening on: <b>Host:</b> %s' % self.server_name,
                '<b>Port:</b> %d' % self.port,
                '<p><ul>'
                '<li>Total <b>Clients:</b> %s' % self.total_clients,
                '<b>Requests:</b> %s' % self.total_requests,
                '<b>Requests/Client:</b> %.1f' % ratio,
                '<li>Total <b>Bytes In:</b> %s' %
                (nice_bytes(self.bytes_in.as_long())),
                '<b>Bytes Out:</b> %s' %
                (nice_bytes(self.bytes_out.as_long())),
                '<li>Total <b>Exceptions:</b> %s' % self.exceptions,
                '</ul><p>'
                '<b>Extension List</b><ul>',
            ])
        ] + handler_stats + [producers.simple_producer('</ul>')])
Exemple #4
0
    def status (self):
        from supervisor.medusa.status_handler import english_bytes
        def nice_bytes (n):
            return ''.join(english_bytes (n))

        handler_stats = [_f for _f in map (maybe_status, self.handlers) if _f]

        if self.total_clients:
            ratio = self.total_requests.as_long() / float(self.total_clients.as_long())
        else:
            ratio = 0.0

        return producers.composite_producer (
                [producers.lines_producer (
                        ['<h2>%s</h2>'                                                  % self.SERVER_IDENT,
                        '<br>Listening on: <b>Host:</b> %s'             % self.server_name,
                        '<b>Port:</b> %d'                                               % self.port,
                         '<p><ul>'
                         '<li>Total <b>Clients:</b> %s'                 % self.total_clients,
                         '<b>Requests:</b> %s'                                  % self.total_requests,
                         '<b>Requests/Client:</b> %.1f'                 % ratio,
                         '<li>Total <b>Bytes In:</b> %s'        % (nice_bytes (self.bytes_in.as_long())),
                         '<b>Bytes Out:</b> %s'                         % (nice_bytes (self.bytes_out.as_long())),
                         '<li>Total <b>Exceptions:</b> %s'              % self.exceptions,
                         '</ul><p>'
                         '<b>Extension List</b><ul>',
                         ])] + handler_stats + [producers.simple_producer('</ul>')]
                )
Exemple #5
0
    def check_hooked(self):
        def f(num_bytes):
            self.test_val('num_bytes', len(test_string))

        p1 = producers.simple_producer(test_string, buffer_size=5)
        p = producers.hooked_producer(p1, f)
        self._check_all(p, test_string)
 def status (self):
     import supervisor.medusa.producers as producers
     return producers.simple_producer (
             '<li> Redirecting Handler %s => %s <b>Hits</b>: %s' % (
                     self.pattern, self.redirect, self.hits
                     )
             )
Exemple #7
0
    def getresponse(self, body):
        self.request["Content-Type"] = "text/xml"
        self.request["Content-Length"] = len(body)
        self.request.push(body)
        connection = get_header(self.CONNECTION, self.request.header)

        close_it = 0
        wrap_in_chunking = 0

        if self.request.version == "1.0":
            if connection == "keep-alive":
                if not self.request.has_key("Content-Length"):
                    close_it = 1
                else:
                    self.request["Connection"] = "Keep-Alive"
            else:
                close_it = 1
        elif self.request.version == "1.1":
            if connection == "close":
                close_it = 1
            elif not self.request.has_key("Content-Length"):
                if self.request.has_key("Transfer-Encoding"):
                    if not self.request["Transfer-Encoding"] == "chunked":
                        close_it = 1
                elif self.request.use_chunked:
                    self.request["Transfer-Encoding"] = "chunked"
                    wrap_in_chunking = 1
                else:
                    close_it = 1
        elif self.request.version is None:
            close_it = 1

        outgoing_header = producers.simple_producer(self.request.build_reply_header())

        if close_it:
            self.request["Connection"] = "close"

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

        # apply a few final transformations to the output
        self.request.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.request.log)
            )
        )

        self.request.channel.current_request = None

        if close_it:
            self.request.channel.close_when_done()
Exemple #8
0
 def status (self):
     return producers.simple_producer (
             '<h2>%s</h2>'                                           % self.SERVER_IDENT
             + '<br><b>Total Sessions:</b> %s'               % self.total_sessions
             + '<br><b>Current Sessions:</b> %d'     % (
                     self.total_sessions.as_long()-self.closed_sessions.as_long()
                     )
             )
Exemple #9
0
 def status (self):
     return producers.simple_producer (
             '<h2>%s</h2>'                                           % self.SERVER_IDENT
             + '<br><b>Total Sessions:</b> %s'               % self.total_sessions
             + '<br><b>Current Sessions:</b> %d'     % (
                     self.total_sessions.as_long()-self.closed_sessions.as_long()
                     )
             )
 def status (self):
     return producers.simple_producer (
             '<li>Server-Side Script Handler'
             + '<ul>'
             + '  <li><b>Hits:</b> %s' % self.hits
             + '  <li><b>Exceptions:</b> %s' % self.exceptions
             + '</ul>'
             )
Exemple #11
0
 def push (self, thing):
     # Sometimes, text gets pushed by XMLRPC logic for later
     # processing.
     if isinstance(thing, str):
         thing = as_bytes(thing)
     if isinstance(thing, bytes):
         thing = producers.simple_producer(thing, buffer_size=len(thing))
     self.outgoing.append(thing)
 def status (self):
     return producers.simple_producer (
             '<li>Server-Side Script Handler'
             + '<ul>'
             + '  <li><b>Hits:</b> %s' % self.hits
             + '  <li><b>Exceptions:</b> %s' % self.exceptions
             + '</ul>'
             )
Exemple #13
0
 def push(self, thing):
     # Sometimes, text gets pushed by XMLRPC logic for later
     # processing.
     if isinstance(thing, str):
         thing = as_bytes(thing)
     if isinstance(thing, bytes):
         thing = producers.simple_producer(thing, buffer_size=len(thing))
     self.outgoing.append(thing)
Exemple #14
0
 def status(self):
     return producers.simple_producer(
         '<li>%s' % html_repr(self)
         + '<ul>'
         + '  <li><b>Total Hits:</b> %s' % self.hit_counter
         + '  <li><b>Files Delivered:</b> %s' % self.file_counter
         + '  <li><b>Cache Hits:</b> %s' % self.cache_counter
         + '</ul>'
     )
 def status (self):
     return producers.simple_producer (
             '<li>%s' % status_handler.html_repr (self)
             + '<ul>'
             + '  <li><b>Total Hits:</b> %s'                 % self.hit_counter
             + '  <li><b>Files Delivered:</b> %s'    % self.file_counter
             + '  <li><b>Cache Hits:</b> %s'                 % self.cache_counter
             + '</ul>'
             )
Exemple #16
0
 def status(self):
     import supervisor.medusa.producers as producers
     return producers.simple_producer(
         '<h2>%s</h2>' % self.SERVER_IDENT +
         '<br>Server: %s' % self.server +
         '<br>Cache Entries: %d' % len(self.cache) +
         '<br>Outstanding Requests: %d' % len(self.request_map) +
         '<br>Forward Requests: %s' % self.forward_requests +
         '<br>Reverse Requests: %s' % self.reverse_requests +
         '<br>Cache Hits: %s' % self.cache_hits)
Exemple #17
0
 def status (self):
     import supervisor.medusa.producers as producers
     return producers.simple_producer (
             '<h2>%s</h2>'                                   % self.SERVER_IDENT
             + '<br>Server: %s'                              % self.server
             + '<br>Cache Entries: %d'               % len(self.cache)
             + '<br>Outstanding Requests: %d' % len(self.request_map)
             + '<br>Forward Requests: %s'    % self.forward_requests
             + '<br>Reverse Requests: %s'    % self.reverse_requests
             + '<br>Cache Hits: %s'                  % self.cache_hits
             )
    def check_chunked (self):
        p1 = producers.simple_producer('the quick brown fox', buffer_size = 5)
        p = producers.chunked_producer(p1, footers=['FOOTER'])
        self._check_all(p, """5\r
the q\r
5\r
uick \r
5\r
brown\r
4\r
 fox\r
0\r
FOOTER\r
\r\n""")
    def check_chunked (self):
        p1 = producers.simple_producer('the quick brown fox', buffer_size = 5)
        p = producers.chunked_producer(p1, footers=['FOOTER'])
        self._check_all(p, """5\r
the q\r
5\r
uick \r
5\r
brown\r
4\r
 fox\r
0\r
FOOTER\r
\r\n""")
Exemple #20
0
    def getresponse(self, body):
        self.request['Content-Type'] = 'text/xml'
        self.request['Content-Length'] = len(body)
        self.request.push(body)
        connection = get_header(self.CONNECTION, self.request.header)

        close_it = 0

        if self.request.version == '1.0':
            if connection == 'keep-alive':
                self.request['Connection'] = 'Keep-Alive'
            else:
                close_it = 1
        elif self.request.version == '1.1':
            if connection == 'close':
                close_it = 1
        elif self.request.version is None:
            close_it = 1

        outgoing_header = producers.simple_producer (
            self.request.build_reply_header())

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

        # prepend the header
        self.request.outgoing.insert(0, outgoing_header)
        outgoing_producer = producers.composite_producer(self.request.outgoing)

        # apply a few final transformations to the output
        self.request.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.request.log
                                )
                        )
                )

        self.request.channel.current_request = None

        if close_it:
            self.request.channel.close_when_done()
    def check_simple (self):
        p = producers.simple_producer(test_string)
        self.test_val('p.more()', test_string[:1024])

        p = producers.simple_producer(test_string, buffer_size = 5)
        self._check_all(p, test_string)
 def check_escaping (self):
     p1 = producers.simple_producer('the quick brown fox', buffer_size = 5)
     p = producers.escaping_producer(p1,
                                     esc_from = ' ',
                                     esc_to = '_')
     self._check_all(p, 'the_quick_brown_fox')
 def check_compressed (self):
     p1 = producers.simple_producer(test_string, buffer_size = 5)
     p = producers.compressed_producer(p1)
     compr_data = self._check_all(p, zlib.compress(test_string, 5))
     self.test_val('zlib.decompress(compr_data)', test_string)
Exemple #24
0
    def done(self):
        """finalize this transaction - send output to the http channel"""

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

        #  --- BUCKLE UP! ----

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

        close_it = 0
        wrap_in_chunking = 0

        if self.version == '1.0':
            if connection == 'keep-alive':
                if 'Content-Length' not in self:
                    close_it = 1
                else:
                    self['Connection'] = 'Keep-Alive'
            else:
                close_it = 1
        elif self.version == '1.1':
            if connection == 'close':
                close_it = 1
            elif 'Content-Length' not in self:
                if 'Transfer-Encoding' in self:
                    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()
 def status (self):
     return producers.simple_producer (
             '<li>Status Extension <b>Hits</b> : %s' % self.hit_counter
             )
Exemple #26
0
    def done (self):
        """finalize this transaction - send output to the http channel"""

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

        #  --- BUCKLE UP! ----

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

        close_it = 0
        wrap_in_chunking = 0

        if self.version == '1.0':
            if connection == 'keep-alive':
                if 'Content-Length' not in self:
                    close_it = 1
                else:
                    self['Connection'] = 'Keep-Alive'
            else:
                close_it = 1
        elif self.version == '1.1':
            if connection == 'close':
                close_it = 1
            elif 'Content-Length' not in self:
                if 'Transfer-Encoding' in self:
                    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()
Exemple #27
0
 def push(self, thing):
     if type(thing) == type(''):
         self.outgoing.append(
             producers.simple_producer(thing, buffer_size=len(thing)))
     else:
         self.outgoing.append(thing)
 def check_hooked (self):
     def f (num_bytes):
         self.test_val('num_bytes', len(test_string))
     p1 = producers.simple_producer(test_string, buffer_size = 5)
     p = producers.hooked_producer(p1, f)
     self._check_all(p, test_string)
 def check_glob (self):
     p1 = producers.simple_producer(test_string, buffer_size = 5)
     p = producers.globbing_producer(p1, buffer_size = 1024)
     self.test_true('1024 <= len(p.more())')
Exemple #30
0
 def push (self, thing):
     if type(thing) == type(''):
         self.outgoing.append(producers.simple_producer(thing,
           buffer_size=len(thing)))
     else:
         self.outgoing.append(thing)
Exemple #31
0
    def done(self, *arg, **kw):

        """ I didn't want to override this, but there's no way around
        it in order to support deferreds - CM

        finalize this transaction - send output to the http channel"""

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

        #  --- BUCKLE UP! ----

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

        close_it = 0
        wrap_in_chunking = 0
        globbing = 1

        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
                    # globbing slows down tail -f output, so only use it if
                    # we're not in chunked mode
                    globbing = 0
                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 = deferring_chunked_producer(
                    deferring_composite_producer(self.outgoing)
                    )
            # prepend the header
            outgoing_producer = deferring_composite_producer(
                [outgoing_header, outgoing_producer]
                )
        else:
            # prepend the header
            self.outgoing.insert(0, outgoing_header)
            outgoing_producer = deferring_composite_producer(self.outgoing)

        # hook logging into the output
        outgoing_producer = deferring_hooked_producer(outgoing_producer,
                                                      self.log)

        if globbing:
            outgoing_producer = deferring_globbing_producer(outgoing_producer)

        self.channel.push_with_producer(outgoing_producer)

        self.channel.current_request = None

        if close_it:
            self.channel.close_when_done()
 def check_composite (self):
     p1 = producers.simple_producer('a'*66, buffer_size = 5)
     p2 = producers.lines_producer(['b']*65)
     p = producers.composite_producer([p1, p2])
     self._check_all(p, 'a'*66 + 'b\r\n'*65)
Exemple #33
0
 def status(self):
     return producers.simple_producer(
         '<li>Status Extension <b>Hits</b> : %s' % self.hit_counter)
 def check_glob (self):
     p1 = producers.simple_producer(test_string, buffer_size = 5)
     p = producers.globbing_producer(p1, buffer_size = 1024)
     self.test_true('1024 <= len(p.more())')
 def check_compressed (self):
     p1 = producers.simple_producer(test_string, buffer_size = 5)
     p = producers.compressed_producer(p1)
     compr_data = self._check_all(p, zlib.compress(test_string, 5))
     self.test_val('zlib.decompress(compr_data)', test_string)
Exemple #36
0
    def done(self, *arg, **kw):
        """ I didn't want to override this, but there's no way around
        it in order to support deferreds - CM

        finalize this transaction - send output to the http channel"""

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

        #  --- BUCKLE UP! ----

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

        close_it = 0
        wrap_in_chunking = 0
        globbing = 1

        if self.version == '1.0':
            if connection == 'keep-alive':
                if not 'Content-Length' in self:
                    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 'Content-Length' in self:
                if 'Transfer-Encoding' in self:
                    if not self['Transfer-Encoding'] == 'chunked':
                        close_it = 1
                elif self.use_chunked:
                    self['Transfer-Encoding'] = 'chunked'
                    wrap_in_chunking = 1
                    # globbing slows down tail -f output, so only use it if
                    # we're not in chunked mode
                    globbing = 0
                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 = deferring_chunked_producer(
                deferring_composite_producer(self.outgoing))
            # prepend the header
            outgoing_producer = deferring_composite_producer(
                [outgoing_header, outgoing_producer])
        else:
            # prepend the header
            self.outgoing.insert(0, outgoing_header)
            outgoing_producer = deferring_composite_producer(self.outgoing)

        # hook logging into the output
        outgoing_producer = deferring_hooked_producer(outgoing_producer,
                                                      self.log)

        if globbing:
            outgoing_producer = deferring_globbing_producer(outgoing_producer)

        self.channel.push_with_producer(outgoing_producer)

        self.channel.current_request = None

        if close_it:
            self.channel.close_when_done()
 def status(self):
     import supervisor.medusa.producers as producers
     return producers.simple_producer(
         '<li> Redirecting Handler %s => %s <b>Hits</b>: %s' %
         (self.pattern, self.redirect, self.hits))
 def check_escaping (self):
     p1 = producers.simple_producer('the quick brown fox', buffer_size = 5)
     p = producers.escaping_producer(p1,
                                     esc_from = ' ',
                                     esc_to = '_')
     self._check_all(p, 'the_quick_brown_fox')
Exemple #39
0
    def sendresponse(self, response):

        headers = response.get("headers", {})
        for header in headers:
            self.request[header] = headers[header]

        if "Content-Type" not in self.request:
            self.request["Content-Type"] = "text/plain"

        if headers.get("Location"):
            self.request["Content-Length"] = 0
            self.request.error(301)
            return

        body = response.get("body", "")
        self.request["Content-Length"] = len(body)

        self.request.push(body)

        connection = get_header(self.CONNECTION, self.request.header)

        close_it = 0
        wrap_in_chunking = 0

        if self.request.version == "1.0":
            if connection == "keep-alive":
                if not self.request.has_key("Content-Length"):
                    close_it = 1
                else:
                    self.request["Connection"] = "Keep-Alive"
            else:
                close_it = 1
        elif self.request.version == "1.1":
            if connection == "close":
                close_it = 1
            elif "Content-Length" not in self.request:
                if "Transfer-Encoding" in self.request:
                    if not self.request["Transfer-Encoding"] == "chunked":
                        close_it = 1
                elif self.request.use_chunked:
                    self.request["Transfer-Encoding"] = "chunked"
                    wrap_in_chunking = 1
                else:
                    close_it = 1
        elif self.request.version is None:
            close_it = 1

        outgoing_header = producers.simple_producer(self.request.build_reply_header())

        if close_it:
            self.request["Connection"] = "close"

        if wrap_in_chunking:
            outgoing_producer = producers.chunked_producer(producers.composite_producer(self.request.outgoing))
            # prepend the header
            outgoing_producer = producers.composite_producer([outgoing_header, outgoing_producer])
        else:
            # fix AttributeError: 'unicode' object has no attribute 'more'
            if (not PY3) and (len(self.request.outgoing) > 0):
                body = self.request.outgoing[0]
                if isinstance(body, unicode):
                    self.request.outgoing[0] = producers.simple_producer(body)

            # prepend the header
            self.request.outgoing.insert(0, outgoing_header)
            outgoing_producer = producers.composite_producer(self.request.outgoing)

        # apply a few final transformations to the output
        self.request.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.request.log)
            )
        )

        self.request.channel.current_request = None

        if close_it:
            self.request.channel.close_when_done()
Exemple #40
0
    def sendresponse(self, response):

        headers = response.get('headers', {})
        for header in headers:
            self.request[header] = headers[header]

        if not self.request.has_key('Content-Type'):
            self.request['Content-Type'] = 'text/plain'

        if headers.get('Location'):
            self.request['Content-Length'] = 0
            self.request.error(301)
            return

        body = response.get('body', '')
        self.request['Content-Length'] = len(body)

        self.request.push(body)

        connection = get_header(self.CONNECTION, self.request.header)

        close_it = 0
        wrap_in_chunking = 0

        if self.request.version == '1.0':
            if connection == 'keep-alive':
                if not self.request.has_key('Content-Length'):
                    close_it = 1
                else:
                    self.request['Connection'] = 'Keep-Alive'
            else:
                close_it = 1
        elif self.request.version == '1.1':
            if connection == 'close':
                close_it = 1
            elif not self.request.has_key ('Content-Length'):
                if self.request.has_key ('Transfer-Encoding'):
                    if not self.request['Transfer-Encoding'] == 'chunked':
                        close_it = 1
                elif self.request.use_chunked:
                    self.request['Transfer-Encoding'] = 'chunked'
                    wrap_in_chunking = 1
                else:
                    close_it = 1
        elif self.request.version is None:
            close_it = 1

        outgoing_header = producers.simple_producer (
            self.request.build_reply_header())

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

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

        # apply a few final transformations to the output
        self.request.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.request.log
                                )
                        )
                )

        self.request.channel.current_request = None

        if close_it:
            self.request.channel.close_when_done()
    def check_simple (self):
        p = producers.simple_producer(test_string)
        self.test_val('p.more()', test_string[:1024])

        p = producers.simple_producer(test_string, buffer_size = 5)
        self._check_all(p, test_string)
Exemple #42
0
    def sendresponse(self, response):

        headers = response.get('headers', {})
        for header in headers:
            self.request[header] = headers[header]

        if not self.request.has_key('Content-Type'):
            self.request['Content-Type'] = 'text/plain'

        if headers.get('Location'):
            self.request['Content-Length'] = 0
            self.request.error(301)
            return

        body = response.get('body', '')
        self.request['Content-Length'] = len(body)

        self.request.push(body)

        connection = get_header(self.CONNECTION, self.request.header)

        close_it = 0
        wrap_in_chunking = 0

        if self.request.version == '1.0':
            if connection == 'keep-alive':
                if not self.request.has_key('Content-Length'):
                    close_it = 1
                else:
                    self.request['Connection'] = 'Keep-Alive'
            else:
                close_it = 1
        elif self.request.version == '1.1':
            if connection == 'close':
                close_it = 1
            elif not self.request.has_key('Content-Length'):
                if self.request.has_key('Transfer-Encoding'):
                    if not self.request['Transfer-Encoding'] == 'chunked':
                        close_it = 1
                elif self.request.use_chunked:
                    self.request['Transfer-Encoding'] = 'chunked'
                    wrap_in_chunking = 1
                else:
                    close_it = 1
        elif self.request.version is None:
            close_it = 1

        outgoing_header = producers.simple_producer(
            self.request.build_reply_header())

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

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

        # apply a few final transformations to the output
        self.request.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.request.log)))

        self.request.channel.current_request = None

        if close_it:
            self.request.channel.close_when_done()
 def check_composite (self):
     p1 = producers.simple_producer('a'*66, buffer_size = 5)
     p2 = producers.lines_producer(['b']*65)
     p = producers.composite_producer([p1, p2])
     self._check_all(p, 'a'*66 + 'b\r\n'*65)