title: Go: unexpected EOF while reading from a socket
body: <p>I have the following simple golang program to download Google's privacy policy. Unfortunately it always crashes with the error <code>unexpected EOF</code> after reading 6861 bytes, even though the document is much longer. Why?</p>
  
  <pre><code>package main
  
  import "net"
  import "fmt"
  import "io"
  import "os"
  
  func die(msg string, s os.Error) {
      fmt.Printf("%s crashed: %v\n", msg, s)
      os.Exit(1)
  }
  
  func main() {
      fd, err := net.Dial("tcp", "google.com:80")
      if err != nil { die("dial", err) }
  
      req := []byte("GET /intl/en/privacy/ HTTP/1.0\r\nHost: www.google.com\r\n\r\n")
      _, err = fd.Write(req)
      if err != nil { die("dial write", err) }
  
      buf := make([]byte, 1024)
      nr := 1
  
      for nr &gt; 0 {
          nr, err = io.ReadFull(fd, buf)
          if err != nil { die("dial read", err) }
          fmt.Printf("read %d\n", nr)
      }
  }
  </code></pre>
  
  <p>outputs:</p>
  
  <pre><code>read 1024
  read 1024
  read 1024
  read 1024
  read 1024
  read 1024
  dial read crashed: unexpected EOF
  </code></pre>