title: Reading http.Response Body stream
body: <p>I'm sending a http request and getting a response in text/xml format. I don't need to parse the XML, just trying to return it as a string for testing. But it seems pretty slow. </p>
  
  <p>The XML response is 278kb, but it can take about 1.7 but sometimes spike to 4.5seconds just to read the response body. I can rerun this over and over and it can vary wildly. I'm not sure what's causing it as i'm new to Go.</p>
  
  <p>I feel like the ioutil.ReadAll() function is letting me down. But i've also tried bufio.NewReader and reader.ReadBytes. All seem to be just as slow. </p>
  
  <p>this is what my function looks like:</p>
  
  <pre><code>client := &amp;http.Client{}
  req, err := http.NewRequest("POST", url, strings.NewReader(requestBody))
  if err != nil {
      fmt.Println("New Request Error", err)
  }
  
  // Set Headers
  req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
  req.Header.Set("Content-Encoding", "gzip")
  req.Header.Set("Accept-Encoding", "gzip, deflate")
  
  defer req.Body.Close()
  
  // Get Response
  startRes := time.Now()
  response, err := client.Do(req)
  if response != nil {
      defer response.Body.Close()
  }
  if err != nil {
      fmt.Println("POST Error", err)
  }
  endRes := time.Now()
  fmt.Println("Response took", endRes.Sub(startRes))
  
  // Read Response Body
  startRead := time.Now()
  body, readErr := ioutil.ReadAll(response.Body)
  if readErr != nil {
      fmt.Println("body error:", readErr)
      return nil, readErr
  }
  
  endRead := time.Now()
  fmt.Println("Read response took:", endRead.Sub(startRead))
  </code></pre>
  
  <p>The output of these println's look like this:</p>
  
  <pre><code>&gt; go run main.go
   Response took 5.230523s
   Read response took: 1.7551755s
  </code></pre>
  
  <p>Is there a way to make this code more efficient? I'm assuming the 1.7s read time for a 278kb file is due to network lag, right? </p>