title: browser doesn't response well to https proxy
body: <p>I'v built my own https proxy and when ever I send some data to a browser the browser responses with nothing and also after a lot of time.
  basically all the proxy should do is just forward the message to browser, get the response and forward back to the client</p>
  <p>the code of the proxy:</p>
  <pre><code>import socket
  import select
  
  
  
  serverSock = socket.socket()
  serverSock.bind(('0.0.0.0', 8080))
  serverSock.listen(3)
  waiting_clients = {} # client : browser
  users_dict = {}
  open_clients = {}
  browsers_clients = {} # browser : client
  
  threading.Thread(target=browserCom).start()
  while True:
      try:
          rlist, wlist, xlist = select.select(list(users_dict.keys()) + [serverSock], [], [], 0.3)
      except:
          pass
      else:
          for current_socket in rlist:
              if current_socket is serverSock:
                  # new client
                  client, address = serverSock.accept()
                  print(f'{address} - connected to proxy')
                  # add to dictionary
                  users_dict[client] = address
                  open_clients[address] = client
              else:
                  # receive info
                  receiving = True
                  msg = bytearray()
                  while receiving:
                      try:
                          data = current_socket.recv(1024)
                      except Exception as e:
                          print(e, 3)
                          if current_socket in users_dict.keys():
                              disconnect(users_dict[current_socket])
  
                          else:
                              current_socket.close()
                          break
                      else:
                          msg.extend(data)
                          # got the full msg
                          if len(data) &lt; 1024:
                              receiving = False
                  if len(msg) == 0:
                      if current_socket in users_dict.keys():
                          disconnect(users_dict[current_socket])
                  else:
  
                      print(&quot;GOT FROM CLIENT&quot;, msg)
                      if current_socket in waiting_clients.keys():
                          # sending  the data from client to browser
                          waiting_clients[current_socket].send(msg)
                      
  
                      else:
                          msg = msg.decode()
                          msgSplit = msg.split()
                          address = msgSplit[1]
  
                          if address.split(':')[1].isnumeric():
                              if msg.startswith('CONNECT'):
                                  browserLink, browserPort = address.split(':')
                                  browserPort = int(browserPort)
                                  browserIP = socket.gethostbyname(browserLink)
                                  address = (browserIP, browserPort)
                                  # connect to the site
                                  browserSocket = socket.socket()
                                  print(address)
                                  browserSocket.connect((browserIP, browserPort))
                                  waiting_clients[current_socket] = browserSocket
                                  browsers_clients[browserSocket] = current_socket
                                  msg_ret = &quot;HTTP/1.1 200 Connection established\r\n\r\n&quot;
                                  sendMsg(users_dict[current_socket], msg_ret)
                                  m
                             
  </code></pre>
  <p>The proxy is able to make the connection after the CONNECT and notify to the client but after I send to the browser I got from the data with a function running in the background:</p>
  <pre><code>def browserCom():
      while True:
          try:
              rlist, wlist, xlist = select.select(list(browsers_clients.keys()), [], [], 0.3)
          except:
              pass
          else:
              for current_browser in rlist:
                  # receive data from the browser
                  receiving = True
                  resp_msg = bytearray()
                  while receiving:
                      try:
                          data = current_browser.recv(1024)
                      except Exception as e:
                          print(e)
                          del waiting_clients[browsers_clients[current_browser]]
                          current_browser.close()
                          browsers_clients[current_browser].close()
                          del browsers_clients[current_browser]
  
                      else:
                          resp_msg.extend(data)
                          # got the full msg
                          if len(data) &lt; 1024:
                              receiving = False
  
                  print(&quot;RESPONSE FROM BROWSER&quot;, resp_msg)
                  # sending the msg to the client
                  sendMsg(users_dict[browsers_clients[current_browser]], resp_msg)
                         
  </code></pre>
  <p>I need to wait a lot of time for the response and most of the responses come empty the responses are mostly bytearray(b'') and even when I get the response even though I sent the response back to the client:</p>
  <pre><code># sending the msg to the client
  sendMsg(users_dict[browsers_clients[current_browser]],resp_msg)
  </code></pre>
  <p>using this</p>
  <pre><code>def sendMsg(address, msg):
          &quot;&quot;&quot;
      
          :param ip: ip to send to
          :param msg: msg to send
          :return: sends the msg to the ip
          &quot;&quot;&quot;
          if address in open_clients.keys():
              sock = open_clients[address]
              if type(msg) == str:
                  msg = msg.encode()
              try:
                  sock.send(msg)
              except Exception as e:
                  print(e, 4)
                  disconnect(address)
      
  </code></pre>
  <p>I hope you are abled to understand my code, please if something is unclear ask me in the comments and I will try to help you understand as soon as possible</p>
  <p>this is the best that I can do to keep the code minimal for this problem without removing crucial parts</p>