Example #1
0
    def found_terminator(self):
        buf, self.buf = self.buf, b""

        #print ("FOUND", repr (buf), '::', self.data_length, self.channel.get_terminator ())
        #print ("FOUND", self.request.version, self.request.command, self.data_length)
        events = None
        if self.request.version == "1.1" and self.data_length:
            self.request.version = "2.0"  # upgrade
            data = self.rfile.getvalue()
            with self._clock:
                r = self.requests[1]
            r.channel.set_data(data, len(data))
            r.set_stream_ended()
            self.data_length = 0
            self.rfile.seek(0)
            self.rfile.truncate()
            self.channel.set_terminator(24)  # for premble

        elif not self._got_preamble:
            if not buf.endswith(b"SM\r\n\r\n"):
                raise ProtocolError("Invalid preamble")
            self._got_preamble = True
            self.channel.set_terminator(9)

        elif self.data_length:
            events = self.set_frame_data(self.rfile.getvalue())
            self.current_frame = None
            self.data_length = 0
            self.rfile.seek(0)
            self.rfile.truncate()
            self.channel.set_terminator(9)  # for frame header

        elif buf:
            self.current_frame, self.data_length = self.frame_buf._parse_frame_header(
                buf)
            self.frame_buf.max_frame_size = self.data_length

            if self.data_length == 0:
                events = self.set_frame_data(b'')
            self.channel.set_terminator(
                self.data_length == 0 and 9
                or self.data_length)  # next frame header

        else:
            raise ProtocolError("Frame decode error")

        if events:
            self.handle_events(events)
Example #2
0
    def _is_extended_connect_frame(self, frame):
        if not isinstance(frame, RequestReceived):
            return False

        method = extract_method_header(frame.headers)
        if method != b"CONNECT":
            return False

        protocol = ""
        for key, value in frame.headers:
            if key in (b':protocol', u':protocol'):
                protocol = isomorphic_encode(value)
                break
        if protocol != b"websocket":
            raise ProtocolError("Invalid protocol %s with CONNECT METHOD" % (protocol,))

        return True
Example #3
0
	def found_terminator (self):
		buf, self.buf = self.buf, b""		
		events = None
		if self.data_length:			
			events = self.set_frame_data (self.rfile.getvalue ())				
			self.data_length = 0
			self.current_frame = None
			self.rfile.seek (0)
			self.rfile.truncate ()
			self.asyncon.set_terminator (9) # for frame header
						
		elif buf:
			self.current_frame, self.data_length = self.frame_buf._parse_frame_header (buf)
			self.frame_buf.max_frame_size = self.data_length
			if self.data_length == 0:
				events = self.set_frame_data (b'')
			self.asyncon.set_terminator (self.data_length == 0 and 9 or self.data_length)	# next frame header
			
		else:
			raise ProtocolError ("Frame decode error")
		
		if events:
			self.handle_events (events)