コード例 #1
0
    def handleData(self):
        if self._packet_len >= self._expected_len:
            type = Packet()
            buf = ''.join(self._packet)
            while len(buf) >= self._expected_len:
                type.unpack(buf)
                if type.length <= len(buf):

                    if type.type in PacketFactory:
                        packet = PacketFactory[type.type]()
                        buf = packet.unpack(buf)
                        if type.type != PACKET_PING:
                            self.log.debug("%s(%d bytes) => %s", self._prefix,
                                           type.length, packet)
                        if self._poll:
                            self.pushPacket(packet)
                        else:
                            self._handler(packet)
                    else:
                        self.log.warn(
                            "%s: unknown message received (id %d, length %d)\n",
                            self._prefix, type.type, type.length)
                        buf = buf[1:]
                    self._expected_len = Packet.format_size
                else:
                    self._expected_len = type.length
            self._packet[:] = [buf]
            self._packet_len = len(buf)
コード例 #2
0
    def test01_rest_filter_finished_request(self):
        """proxyfilter.rest_filter should ignore finished request"""
        class Transport:
            def write(self, data):
                pass

        class Channel:
            transport = Transport()

            def requestDone(self, request):
                pass

        class Service:
            verbose = 6

            def packet2resthost(self, packet):
                return (None, None, None)

        class Resource:
            service = Service()

        class Site:
            resource = Resource()

        class Packet:
            pass

        r = pokersite.Request(Channel(), True)
        pinput = '{"type": "PacketPing"}'
        r.gotLength(len(pinput))
        r.handleContentChunk(pinput)
        r.setResponseCode(http.OK)
        r.write("FINISHED")
        r.finish()
        r.noLongerQueued()
        proxyfilter.rest_filter(Site(), r, Packet())