title: What can cause Rust's TcpSocket::write() to return "invalid input"?
body: <p><a href="https://codegolf.stackexchange.com/questions/44278/debunking-stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro">For a little fun</a> I wanted to make a simple HTTP request in Rust. I threw this together and it works great:</p>
  
  <pre><code>use std::io::TcpStream;
  
  fn main() {
      // This just does a "GET /" to www.stroustrup.com
      println!("Establishing connection...");
      let mut stream = TcpStream::connect("www.stroustrup.com:80").unwrap();
  
      println!("Writing HTTP request...");
      // unwrap() the result to make sure it succeeded, at least
      let _ = stream.write(b"GET / HTTP/1.1\r\n\
                             Host: www.stroustrup.com\r\n\
                             Accept: */*\r\n\
                             Connection: close\r\n\r\n").unwrap();
  
      println!("Reading response...");
      let response = stream.read_to_string().unwrap();
  
      println!("Printing response:");
      println!("{}", response);
  }
  </code></pre>
  
  <p>Response is:</p>
  
  <pre><code>Establishing connection...
  Writing HTTP request...
  Reading response...
  Printing response:
  HTTP/1.1 200 OK
  ...and the rest of the long HTTP response with all the HTML as I'd expect...
  </code></pre>
  
  <p>However, if I change the request to be <code>/C++.html</code> instead of <code>/</code>:</p>
  
  <pre><code>use std::io::TcpStream;
  
  fn main() {
      // The only change is to "GET /C++.html" instead of "GET /"
      println!("Establishing connection...");
      let mut stream = TcpStream::connect("www.stroustrup.com:80").unwrap();
  
      println!("Writing HTTP request...");
      // unwrap() the result to make sure it succeeded, at least
      let _ = stream.write(b"GET /C++.html HTTP/1.1\r\n\
                             Host: www.stroustrup.com\r\n\
                             Accept: */*\r\n\
                             Connection: close\r\n\r\n").unwrap();
  
      println!("Reading response...");
      let response = stream.read_to_string().unwrap();
  
      println!("Printing response:");
      println!("{}", response);
  }
  </code></pre>
  
  <p>The socket returns <code>"invalid input"</code>:</p>
  
  <pre><code>Establishing connection...
  Writing HTTP request...
  Reading response...
  thread '&lt;main&gt;' panicked at 'called `Result::unwrap()` on an `Err` value: invalid input', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libcore/result.rs:746
  </code></pre>
  
  <p>Why does the socket return <code>"invalid input"</code>? The TCP socket isn't aware of the HTTP protocol (and I've tested my request with telnet and netcat: it's correct), so it can't be complaining about HTTP request/response.</p>
  
  <p>What does <code>"invalid input"</code> even mean here? Why doesn't this work?</p>
  
  <p>My rust version (I'm on OS X 10.10.1):</p>
  
  <pre><code>$ rustc --version
  rustc 1.0.0-nightly (ea6f65c5f 2015-01-06 19:47:08 +0000)
  </code></pre>