title: in a proxy, formatting a browser request before sending it out to the host
body: <p>For class, I'm writing a basic proxy server in c.</p>
  
  <p>In the professor's example (which is java), he takes the browser's request, which looks like this:</p>
  
  <pre><code>GET http://www.cs.rpi.edu/index.html HTTP/1.1
  Host: www.cs.rpi.edu
  User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language: en-us,en;q=0.5
  Accept-Encoding: gzip, deflate
  Proxy-Connection: keep-alive
  Cookie: __utma=138860844.163543584.1329315062.1329315062.1329315062.1;__utmz=138860844.1329315062.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)
  Cache-Control: max-age=0
  </code></pre>
  
  <p>And formats it to look like this, plus the Accept and User-Agent headers, before sending it out to the host server:</p>
  
  <pre><code>GET /index.html HTTP/1.1
  Host: www.cs.rpi.edu
  </code></pre>
  
  <p>I've done this also, but now I run into 2 problems, and 1 question:</p>
  
  <p>A. The message sends to the server okay, because connect() and write() don't give me any error, but when I go to read() the server response (perhaps wrongfully expecting HTML?), the program freezes and just sits forever until I ctrl+C. I cannot for the life of me find a cause:</p>
  
  <pre><code>  /* write a message out on the socket connection */
    int n = write( sock, clientrequest, strlen( clientrequest ) );
  
    if ( n &lt; strlen( clientrequest ) )
    {
      perror( "write() failed" );
      return EXIT_FAILURE;
    }
  
    printf("Made it here.\n\n");
  
    char buffer2[1024];
    n = read( sock, buffer2, 1024 );
    if ( n &lt; 1 )
    {
      perror( "read() failed" );
      return EXIT_FAILURE;
    }
    else
    {
      buffer2[n] = '\0';
      printf( "Rcvd message from server: \n\n----\n\n%s\n\n----\n\n", buffer2 );
    }
  
    printf("But not here.\n\n");
  </code></pre>
  
  <p>B. Say I'm connecting to something like www.google.com. There is no /index.html, so what should go after the GET in the formatted request?</p>
  
  <p>C. Why does the request need to be formatted in this fashion, rather than just sent out as is?</p>