コード例 #1
0
 def client_encode(self, buf):
     raise Exception('Need to finish')
     if self.has_sent_header:
         return buf
     port = b''
     if self.server_info.port != 80:
         port = b':' + to_bytes(str(self.server_info.port))
     hosts = (self.server_info.obfs_param or self.server_info.host)
     pos = hosts.find("#")
     if pos >= 0:
         body = hosts[pos + 1:].replace("\\n", "\r\n")
         hosts = hosts[:pos]
     hosts = hosts.split(',')
     host = random.choice(hosts)
     http_head = b"GET /" + b" HTTP/1.1\r\n"
     http_head += b"Host: " + to_bytes(host) + port + b"\r\n"
     http_head += b"User-Agent: curl/" + self.curl_version + b"\r\n"
     http_head += b"Upgrade: websocket\r\n"
     http_head += b"Connection: Upgrade\r\n"
     http_head += b"Sec-WebSocket-Key: " + common.to_bytes(
         common.random_base64_str(64)) + b"\r\n"
     http_head += b"Content-Length: " + len(buf) + b"\r\n"
     http_head += b"\r\n"
     self.has_sent_header = True
     return http_head + buf
コード例 #2
0
    def server_encode(self, buf):
        if self.has_sent_header:
            return buf

        header = b'HTTP/1.1 101 Switching Protocols\r\n'
        header += b'Server: nginx/' + self.nginx_version + b'\r\n'
        header += b'Date: ' + to_bytes(datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S GMT'))
        header += b'\r\n'
        header += b'Upgrade: websocket\r\n'
        header += b'Connection: Upgrade\r\n'
        header += b'Sec-WebSocket-Accept: ' + common.to_bytes(common.random_base64_str(64)) + b'\r\n'
        header += b'\r\n'
        self.has_sent_header = True
        return header + buf
コード例 #3
0
    def server_encode(self, buf):
        if self.has_sent_header:
            return buf

        data = b''.join([b'HTTP/1.1 101 Switching Protocols\r\n',
                         b'Server: nginx/',
                         self.nginx_version,
                         b'\r\n',
                         b'Date: ',
                         to_bytes(datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S GMT')),
                         b'\r\n',
                         b'Upgrade: websocket\r\n',
                         b'Connection: Upgrade\r\n',
                         b'Sec-WebSocket-Accept: ',
                         common.to_bytes(common.random_base64_str(64)),
                         b'\r\n',
                         b'\r\n',
                         buf])

        self.has_sent_header = True
        return data