title: net.Conn never receiving EOF
body: <p>I'm trying to send an HTTP request over a <code>net.Conn</code> TCP connection and read the subsequent response, but I never seem to receive an <code>EOF</code> from the connection when reading. This makes functions like <code>io.Copy</code> or <code>ioutil.ReadAll</code> useless, as they block forever.</p>
  <h3>Code:</h3>
  <p><code>client.go</code></p>
  <pre class="lang-golang prettyprint-override"><code>const requestString = &quot;GET /test HTTP/1.1\r\n&quot; + &quot;Host: 127.0.0.1:8080\r\n\r\n&quot;
  
  func main() {
      dialer := net.Dialer{}
      conn, err := dialer.Dial(&quot;tcp&quot;, &quot;127.0.0.1:8080&quot;)
      if err != nil {
          log.Fatalln(err)
      }
  
      defer conn.Close()
  
      _, err = conn.Write([]byte(requestString))
      if err != nil {
          log.Fatalln(err)
      }
      
      buf := make([]byte, 1024)
      data := make([]byte, 0)
      length := 0
  
      for {
          n, err := conn.Read(buf)
          if err != nil {
              if err != io.EOF {
                  fmt.Printf(&quot;Read error: %v\n&quot;, err)
              }
              break
          }
  
          data = append(data, buf[:n]...)
          length += n
          fmt.Printf(&quot;Partial read:\n%s\n&quot;, string(buf[:n]))
      }
  
      fmt.Println(&quot;Response:&quot;)
      fmt.Println(string(data))
  }
  </code></pre>
  <p><code>server.go</code></p>
  <pre class="lang-golang prettyprint-override"><code>func main() {
      http.HandleFunc(&quot;/&quot;, func(w http.ResponseWriter, r *http.Request) {
          fmt.Fprintf(w, &quot;Hello, %s&quot;, r.URL.Path[1:])
      })
      http.ListenAndServe(&quot;:8080&quot;, nil)
  }
  </code></pre>
  <p>Output of running <code>client.go</code> with <code>server.go</code> already running:</p>
  <pre><code>Partial read:
  HTTP/1.1 200 OK
  Date: Wed, 25 Nov 2020 04:09:32 GMT
  Content-Length: 11
  Content-Type: text/plain; charset=utf-8
  
  Hello, test
  </code></pre>
  <p>The first call to <code>Read()</code> returns the expected response, but lacks an <code>EOF</code>. The subsequent call to <code>Read()</code> hangs forever, and I'm not sure how to determine when the connection has finished. If I interrupt the server process, the client connection closes properly and the response is complete.</p>
  <p>How can I either a) receive an <code>EOF</code> or b) determine when the response is complete? All examples I've seen online have something close to my code working, so I'm not sure what I'm doing wrong.</p>