title: Parse HTTP requests and responses from text file in Go
body: <p>Given the following file which holds a HTTP pipelined stream of HTTP requests and HTTP responses.</p>
  
  <p><strong>How can I parse this file into my <code>stream</code> variable?</strong></p>
  
  <pre><code>type Connection struct{
     Request *http.Request
     Response *http.Response
  }
  stream := make([]Connection, 0)
  </code></pre>
  
  <p>The raw file:</p>
  
  <pre><code>GET /ubuntu/dists/trusty/InRelease HTTP/1.1
  Host: archive.ubuntu.com
  Cache-Control: max-age=0
  Accept: text/*
  User-Agent: Debian APT-HTTP/1.3 (1.0.1ubuntu2)
  
  HTTP/1.1 404 Not Found
  Date: Thu, 26 Nov 2015 18:26:36 GMT
  Server: Apache/2.2.22 (Ubuntu)
  Vary: Accept-Encoding
  Content-Length: 311
  Content-Type: text/html; charset=iso-8859-1
  
  &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;404 Not Found&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Not Found&lt;/h1&gt;
  &lt;p&gt;The requested URL /ubuntu/dists/trusty/InRelease was not found on this server.&lt;/p&gt;
  &lt;hr&gt;
  &lt;address&gt;Apache/2.2.22 (Ubuntu) Server at archive.ubuntu.com Port 80&lt;/address&gt;
  &lt;/body&gt;&lt;/html&gt;
  GET /ubuntu/dists/trusty-updates/InRelease HTTP/1.1
  Host: archive.ubuntu.com
  Cache-Control: max-age=0
  Accept: text/*
  User-Agent: Debian APT-HTTP/1.3 (1.0.1ubuntu2)
  
  HTTP/1.1 200 OK
  Date: Thu, 26 Nov 2015 18:26:37 GMT
  Server: Apache/2.2.22 (Ubuntu)
  Last-Modified: Thu, 26 Nov 2015 18:03:00 GMT
  ETag: "fbb7-5257562a5fd00"
  Accept-Ranges: bytes
  Content-Length: 64439
  Cache-Control: max-age=382, proxy-revalidate
  Expires: Thu, 26 Nov 2015 18:33:00 GMT
  
  -----BEGIN PGP SIGNED MESSAGE-----
  Hash: SHA512
  
  Origin: Ubuntu
  Label: Ubuntu
  Suite: trusty-updates
  Version: 14.04
  Codename: trusty
  [... truncated by author]
  </code></pre>
  
  <p>I know there is <a href="https://golang.org/pkg/net/http/#ReadRequest" rel="noreferrer">http.ReadRequest</a>. What about the Response? Any ideas/feedback/thoughts are appreciated.</p>