title: Trying to write a proxy server. Content Length MANAGEMENT problem
body: <p>I am trying to write a proxy server in C language under Linux. It was working fine (I had the perception that it was working fine) until I tried it for streaming media.</p>
  
  <p>Lemme first tell the problem and then I'll jump onto streaming media.
  To read the incoming data from the website and forward it to the actual client I do this</p>
  
  <pre><code>count = read(websitefd,buffer,BUFSIZ);
  
  write(clientfd,buffer,count);` 
  </code></pre>
  
  <p>in a continuous while loop until I read up all the data on that socket.</p>
  
  <p>Now the problem is if the actual website sends an HTTP packet with content length field as 1025 bytes and other part of data in other packets then still I always wait for BUFSIZ(8192 bytes) and then I send 8192 bytes to the client machine all together. for normal <code>octet-stream</code> it works fine even though I know its not the right method, because I should forward the packets same as the actual server. So if actual server sends me 2 packet of sizes 1024 and 1024 bytes I send the client a packet of 2048 bytes with the first packet with the HTTP header saying that the content length is 900 bytes (rest all being the http header assuming) but actually I forward a packet of 2048 bytes to client. For Content Type: application/octet-stream it just downloads the whole thing and displays it either as image or html text or asks me to save it. </p>
  
  <p>When the client request for a streaming media, because of the above reason the client is not able to play the video. So what should I do now ? Thanks for reading my question. Please help me out. :)</p>