title: HTTPS proxy with support for chunked-encoded requests
body: <p>I'm developing a simple HTTPS proxy (written in Python) which receives POST/GET requests/responses, applies some transformation and finally forwards the result to the recipient.
  I need to handle chunked-encoded requests/responses in a "streaming" fashion, meaning that as soon as a chunk is received the proxy transforms it and forwards it to the recipient.</p>
  
  <p>Before deciding to support chunked-encoded requests, I've been using mitmproxy <a href="http://mitmproxy.org/">http://mitmproxy.org/</a> and it worked perfectly. Unfortunately, I noticed that it waits until the entire body is received before letting me handle the response/request.</p>
  
  <p>How can I implement a proxy supporting chunked-encoded requests/responses? Has anyone of you ever done something like this?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT: MORE INFO ON MY USE CASE</strong></p>
  
  <p>I need to handle POST requests and GET responses.</p>
  
  <p>In the <strong>POST request</strong> I receive a JSON object and I have to encrypt some of its values.</p>
  
  <p>In the <strong>GET response</strong> I receive a JSON object and I have to decrypt some of its values.</p>
  
  <p>Till now, the following code has worked perfectly:</p>
  
  <pre><code> def handle_request(self, r):
      if(r.method=='POST'):
         // encryption of r.get_form_urlencoded()
  
   def handle_response(self, r):
      if(r.request.method=='GET'):
         // decryption of r.content
  </code></pre>
  
  <p>How can I do the same thing with single chunks?</p>
  
  <p><strong>EDIT: UPDATES</strong></p>
  
  <p>After evaluating different solutions, I decided to go for Squid (proxy) + ICAP (content adaptation).</p>
  
  <p>I've successfully configured Squid and the performance are just great. Unfortunately, I can't find a suitable ICAP server (in Python, if possible) for doing content adaptation (modification). I thought this one <a href="https://github.com/netom/pyicap">https://github.com/netom/pyicap</a> could do the job but looks like it doesn't read the body of myPOST requests.</p>
  
  <p>Do you guys know a Python ICAP server that I can use together with Squid?</p>
  
  <p>Thanks</p>