Ejemplo n.º 1
0
 def sendEval(self, conn):
     stream = conn.getStream(self.streamID)
     self.headerFlagment = HPACK.encode(dict2list(stream.headers), False, False, False, conn.table)
     #TODO:this should be implemented in connection
     if self.flags&FLAG.PRIORITY == FLAG.PRIORITY:
         stream.weight = self.weight
         stream.setParentStream(self.E, conn.getStream(self.streamDependency))
     if stream.state == STATE.IDLE:
         conn.setStreamState(self.streamID, STATE.OPEN)
     elif stream.state == STATE.RESERVED_L:
         conn.setStreamState(self.streamID, STATE.HCLOSED_R)
Ejemplo n.º 2
0
    def validateData(self):
        if self.preface:
            headerOctet = self._recv(9)
            if len(headerOctet) == 0:
                # when connection closed from client
                self.preface = False
                return False
            info = Http2Header.getHeaderInfo(headerOctet)
            if not self.is_goaway or self.is_goaway and (info.type == TYPE.HEADERS or
                                                         info.type == TYPE.PRIORITY or
                                                         info.type == TYPE.CONTINUATION):
                stream = self.getStream(info.streamID)
                if not stream:
                    self.addStream(info.streamID)
                    stream = self.getStream(info.streamID)

                frameFunc = getFrameFunc(info.type)
                frame = frameFunc(info, self._recv(info.length))
                if info.flags&FLAG.END_HEADERS == FLAG.END_HEADERS:
                    stream.setHeaders(list2dict(HPACK.decode(stream.headerFlagment+frame.headerFlagment, self.table)))
                print "%s\n\t%s\n\t%s" % (recvC.apply("RECV"), stream.string(), frame.string())

                if stream.continuing and info.type != TYPE.CONTINUATION:
                    self.sendFrame(Goaway(self.lastStreamID, err=ERR_CODE.PROTOCOL_ERROR))
                if (stream.getState() == STATE.CLOSED and
                    info.type != TYPE.PRIORITY and
                    info.type != TYPE.RST_STREAM):
                    self.sendFrame(Rst_Stream(info.streamID, err=ERR_CODE.STREAM_CLOSED))
                frame.recvEval(self)
            else:
                self._recv(info.length)
        else:
            data = self._recv(24)
            if data == CONNECTION_PREFACE:
                self.preface = True
        return True
Ejemplo n.º 3
0
 def sendEval(self, conn):
     self.headerFlagment = HPACK.encode(dict2list(conn.getStream(self.streamID).headers), False, False, False, conn.table)
     if conn.getStreamState(self.streamID) == STATE.IDLE:
         conn.setStreamState(self.streamID, STATE.RESERVED_L)