title: Redirecting HTTP Requests
body: <p>I am working on creating plug-and-play software for cameras behind a firewall. To do that, the camera has a command that tells it to connect to a server of mine (over http), in which I can talk to it in http.</p>
  
  <p>I need to export this connection to users, so that when I get http requests, I forward them directly to the camera, and forward the responses back to the user.</p>
  
  <p>My initial idea was just to use tcp - get the camera connection using tcp, and continuously wait for user connections. When I get a user connection - I forward everything from it to the camera, and from the camera to it. In other words - plain old port redirection.</p>
  
  <p>The problem begins when the user needs to have several active connections to the camera. I hoped this would not be an issue - but I have found out (or at least that's what I think happens) that browsers actually open several connections to the same site to download files.</p>
  
  <p>Now I have no choice but to write code that actually reads the http request, dispatches it to the camera, waits for the camera's response, and sends it back. 
  That is the only way to allow multiple connections to the same camera using just one connection (as far as I can see).</p>
  
  <p>My question is - is there any existing code to do this? Libraries? Software? Or is there any better way to do what I'm trying to do?</p>
  
  <p>EDIT: Well, apparently I was wrong about the browser creating several connections to the server. What actually happens is that the server returns HTTP 1.0 responses, and as I have found out, HTTP 1.0 allows a single request (and response) per connection. What I was seeing is the browser just leaving the used connection it has opened earlier open, and opening a new one for a new request.</p>
  
  <p>However, I still had to do HTTP message forwarding myself (I only implemented "text/html", "text/plain" and some other custom content type which is used by the camera). So for instance, the browser doesn't show pictures at all. So if anyone knows about any code that does http message forwarding (or an application that does it), I would love to hear it.</p>
  
  <p>As a side note - I have checked the proxy feature of httpd (apache). Not only is it very complicated, it also seems to allow only one proxy connection on the machine. So I abandoned that direction and implemented basic forwarding myself.</p>
  
  <p>Thanks</p>