title: How to connect a client to a server through an HTTP proxy in Python?
body: <p>I'm really new to coding using sockets.</p>
  
  <p>I like the socket library, I get to understand a big part of what's happening in my program, so i you don't mind i would like to stick with it.</p>
  
  <p>So as the title says, I have a socket based client and server and I would like to exchange content through an HTTP proxy(I'm using a Squid proxy). This little piece of code is supposed to bypass the proxy in my campus to simulate a chat over the campus network. This is totally legal since I asked the IT guys that work there.</p>
  
  <p>Here's the deal, I am able to send a POST request through the proxy to my server which receives it and sends it back to client 1, but when I try to send more requests to the proxy none of them gets to the server so I think to my self the connection died but here's the thing, when I send messages from client 2 which is connected directly to the server, the server AND client 1 receive them.</p>
  
  <pre><code>import socket
  from _thread import *
  
  def sender(server,h):
      b=input("&lt;&lt;--Send--")
      b=h
      server.send(b.encode())
  
  PROXY_IP="127.0.0.1"
  PROXY_PORT=3128
  server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  server.settimeout(0.05)
  server.connect((PROXY_IP,PROXY_PORT))
  
  header="""POST http://127.0.0.1:3001 HTTP/1.1\r\n
  Host: 127.0.0.1:3001\r\n
  Proxy-Connection: keep-alive\r\n
  Content-Length: 5 \r\n\r\n
  hello\r\n"""
  
  server.send(header.encode())
  
  while 1:
      try:
          start_new_thread(sender,(server,header))
          a=server.recv(1024)
          print("--&gt;&gt;{}".format(a.decode()))
      except KeyboardInterrupt:
          break
      except:
          pass
  
  server.close()
  </code></pre>
  
  <p>I already tried the CONNECT method which works perfectly, but it's not allowed in my campus network proxy.
  What am I doing wrong ?
  Is there something I should know about how to re-send content through a proxy ?
  Thank you for your time and please bear with me..</p>
  
  <p>Here's what I get on the client that sends a request to the proxy:</p>
  
  <pre><code>~#Sent : POST http://127.0.0.1:3001 HTTP/1.1
  Host: 127.0.0.1:3001
  Proxy-Connection: keep-alive
  Content-Length: 5 
  
  hello
  
  #Received : HTTP/1.1 200 OK
  Server: squid/3.5.19
  Mime-Version: 1.0
  Date: Mon, 10 Oct 2016 00:46:39 GMT
  X-Transformed-From: HTTP/0.9
  X-Cache: MISS from kali
  X-Cache-Lookup: MISS from kali:3128
  Transfer-Encoding: chunked
  Via: 1.1 kali (squid/3.5.19)
  Connection: keep-alive
  
  
  #Received : B2
  POST / HTTP/1.1
  Content-Length: 5
  Host: 127.0.0.1:3001
  Via: 1.1 kali (squid/3.5.19)
  X-Forwarded-For: 127.0.0.1
  Cache-Control: max-age=259200
  Connection: keep-alive
  
  hello
  
  
  #Sent : POST http://127.0.0.1:3001 HTTP/1.1
  Host: 127.0.0.1:3001
  Proxy-Connection: keep-alive
  Content-Length: 5 
  
  hello
  </code></pre>
  
  <p>Nothing is received after this..</p>