def __init__(self, id, end_stream=False): self.is_end_stream = end_stream self._is_padded = False Frame.__init__(self, type=FrameType.DATA, flag=0x0, id=id)
def __init__(self, id, window_size=1): Frame.__init__( self, type=FrameType.WINDOW_UPDATE, flag=0x0, id=id, data=None ) self.window_size = window_size
def __init__(self, last_stream_id, error_code, debug_data): Frame.__init__( self, type=FrameType.GOAWAY, flag=0x0, id=0x0, data=None ) self.last_stream_id = last_stream_id self.error_code = error_code self.debug_data = debug_data
def __init__(self, id, header_list=[], end_header=True, end_stream=False): self.is_end_stream = end_stream self.is_end_header = end_header self._is_priority = False self._is_padded = False self._header_list = header_list # http header list self._encoded_data = None Frame.__init__(self, type=FrameType.HEADERS, flag=0x0, id=id, data=None)
def __init__(self, id, header_list=[], end_header=True): self.is_end_header = end_header self._is_priority = False self._is_padded = False self._header_list = header_list # http header list self._encoded_data = None self.promised_stream_id = 0x0 # default Frame.__init__(self, type=FrameType.PUSH_PROMISE, flag=0x0, id=id, data=None)
def run_stream(self, rfile, frame_header): (frame_len, frame_type, frame_flag, frame_id) = frame_header raw_frame_payload = rfile.read(frame_len) frame = Frame.load( frame=raw_frame_payload, header=frame_header, decoder=self.conn.decoder ) self.recv_frame(frame) if self.is_recv_end_header and not self.is_run_app: self.is_run_app = True self.run_with_dogu( ( self.command, self.path, self.http_version, self.recv_headers, ), self.request_payload_stream ) if self.is_wait_res and not self.sending: self.sending = True # start send self.conn.flush() return True
def get_frame_bin(self): if self._data is None and not self.is_ack: # If user didn't set data self._data = bytearray() for setting in self._setting_list: # set identifier 16 bit self._data.append((setting[0] & 0x0000FF00) >> 8) self._data.append((setting[0] & 0x000000FF) >> 0) # set value 32 bit self._data.append((setting[1] & 0xFF000000) >> 24) self._data.append((setting[1] & 0x00FF0000) >> 16) self._data.append((setting[1] & 0x0000FF00) >> 8) self._data.append((setting[1] & 0x000000FF) >> 0) elif self.is_ack: # if ACK SETTINGS frame clear payload self._data = bytearray() self._flag = SettingFrame.ACK_FLAG # call super get_frame_bin return Frame.get_frame_bin(self)
def get_frame_bin(self): # Encode header encoder = Encoder() headers_frame_field = bytearray() if self._data is None: # if user didn't touch data self._data = encoder.encode(self._header_list) # encode header list self._flag = self.flag # get flag by method if self._is_padded: headers_frame_field.append(self._pad_len) # append pad length self._data += bytearray(self._pad_len) # append pad byte in pad length if self._is_priority: headers_frame_field += int_to_bytes(self._dependency_id, 4) # append dependency stream id headers_frame_field.append(self._weight) self._data = headers_frame_field + self._data # append HEADERS field return Frame.get_frame_bin(self)
def get_frame_bin(self): if self._data is None: # if user didn't touch data self._data = bytearray() self._data += int_to_bytes(self._dependency_id) # append dependency stream id self._data.append(self._weight) return Frame.get_frame_bin(self)
def get_frame_bin(self): if self._data is None: # if user didn't touch data self._data = bytearray() self._data += self.opaque if self.ack: self._flag = 0x1 return Frame.get_frame_bin(self)
def get_frame_bin(self): if self._data is None: self._data = bytearray() self._data += int_to_bytes(self.last_stream_id, 4) self._data += int_to_bytes(self.error_code, 4) self._data = self.debug_data.encode(GoawayFrame.GOAWAY_DEBUG_ENCODING) return Frame.get_frame_bin(self)
def get_frame_bin(self): headers_frame_field = bytearray() if self._data is None: self._data = bytearray() # check for safe self._flag = self.flag # get flag by method if self._is_padded: headers_frame_field.append(self._pad_len) # append pad length self._data += bytearray(self._pad_len) # append pad byte in pad length self._data = headers_frame_field + self._data # append HEADERS field return Frame.get_frame_bin(self)
def run(self): while True: raw_frame_header = self.rfile.read( HTTP2Connection.STREAM_HEADER_SIZE ) if len(raw_frame_header) == 0: # user close connection logger.debug('user close connection') return try: frame_header = Frame.parse_header( raw_frame_header[:HTTP2Connection.STREAM_HEADER_SIZE] ) (frame_len, frame_type, frame_flag, frame_id) = frame_header try: target_stream = self.get_stream(frame_id) except StreamClosedError: # if closed error if not (frame_type == FrameType.WINDOW_UPDATE or frame_type == FrameType.RST_STREAM or frame_type == FrameType.PRIORITY): logger.debug('User send frame in closed stream(frame_type: %d)', frame_type) raise StreamClosedError('User send frame in closed stream(frame_type: %d)' % frame_type) # close connection if not target_stream.run_stream(self.rfile, frame_header): break sleep(0) except HTTP2Error as e: if self.server_setting['debug']: import traceback traceback.format_exc() logger.error('Goaway id %d debug data: %s', e.code, e.debug_data) goaway = GoawayFrame(frame_id, e.code, e.debug_data) self.write(goaway.get_frame_bin()) print("close connection") return
def __init__(self, opaque, ack): self.ack = ack self.opaque = opaque Frame.__init__(self, type=FrameType.PING, flag=0x0, id=0x0, data=None)
def __init__(self, id, error_code): self.error_code = error_code Frame.__init__(self, type=FrameType.PRIORITY, flag=0x0, id=id, data=None)
def get_frame_bin(self): if self._data is None: # if user didn't touch data self._data = int_to_bytes(self.error_code, 4) return Frame.get_frame_bin(self)
def __init__(self, is_ack=False): self._setting_list = [] self.is_ack = is_ack # is frame ACK SETTINGS frame Frame.__init__(self, type=FrameType.SETTINGS, flag=0x0, id=0x0, data=None)
def __init__(self, id, dep_stream_id, weight): self._dependency_id = dep_stream_id self._weight = weight Frame.__init__(self, type=FrameType.PRIORITY, flag=0x0, id=id, data=None)
def get_frame_bin(self): if self._data is None: self._data = int_to_bytes(self.window_size, 4) return Frame.get_frame_bin(self)