title: Retrieve image from HTTP response body
body: <p>I am trying to retrieve an image from a Server via an HTTP GET request in my Client service.
  I reproduced my use case in the following code:</p>
  
  <p>main.go: </p>
  
  <pre><code>package main
  
  import (
      "net/http"
      "os"
  
      "github.com/gorilla/mux"
      log "github.com/sirupsen/logrus"
  )
  
  func main() {
      log.SetFormatter(&amp;log.TextFormatter{})
  
      // Initialize router
      router := mux.NewRouter()
  
      args := os.Args
  
      if args[1] == "client" {
          log.Print("Run Client, listening on port 8080")
          router.Methods("GET").Path("/image").HandlerFunc(ClientGetImage)
          log.Fatal(http.ListenAndServe(":8080", router))
      } else if args[1] == "server" {
          log.Print("Run Server, listening on port 4242")
          router.Methods("GET").Path("/image").HandlerFunc(ServerGetImage)
          log.Fatal(http.ListenAndServe(":4242", router))
      } else {
          log.Fatal("Wrong command. Choose [client] or [server] option")
      }
  }
  </code></pre>
  
  <p>client.go:</p>
  
  <pre><code>package main
  
  import (
      "image"
      "log"
      "net/http"
  )
  
  func ClientGetImage(w http.ResponseWriter, r *http.Request) {
      // Make HTTP Get request to retrieve the image from the server
      log.Print("Requesting image to server")
      resp, err := http.Get("http://localhost:4242/image")
  
      if err != nil {
          log.Fatal(err)
      }
      defer resp.Body.Close()
  
      m, _, err := image.Decode(resp.Body)
      if err != nil {
          log.Fatal(err)
      }
  
      log.Print("Pixels: ", m)
  }
  </code></pre>
  
  <p>server.go:</p>
  
  <pre><code>package main
  
  import (
      "bytes"
      "image"
      "image/color"
      "image/jpeg"
      "log"
      "net/http"
      "strconv"
  )
  
  func ServerGetImage(w http.ResponseWriter, r *http.Request) {
      img := image.NewGray16(image.Rect(0, 0, 1, 1))
      img.SetGray16(0, 0, color.Gray16{Y: 42000})
  
      // Print created
      log.Print("Pixels: ", img)
  
      buffer := new(bytes.Buffer)
      if err := jpeg.Encode(buffer, img, nil); err != nil {
          log.Println("unable to encode image.")
      }
  
      w.Header().Set("Content-Type", "image/jpeg")
      w.Header().Set("Content-Length", strconv.Itoa(len(buffer.Bytes())))
      if _, err := w.Write(buffer.Bytes()); err != nil {
          log.Println("unable to write image.")
      }
  }
  </code></pre>
  
  <p>The purpose is pretty simple: upon reception of a GET request, the client sends a GET request to the server to retrieve an image.
  Upon reception of the Client's GET request, the server creates a 1x1 image, encoded in 16bits.</p>
  
  <p>After running my client and server, when I send a my GET request to the client, I get the following logs:</p>
  
  <p>Server logs:</p>
  
  <pre><code>INFO[0000] Run Server, listening on port 4242           
  2019/09/30 15:32:05 Pixels: &amp;{[164 16] 2 (0,0)-(1,1)}
  </code></pre>
  
  <p>Client logs:</p>
  
  <pre><code>INFO[0000] Run Client, listening on port 8080           
  2019/09/30 15:41:52 Requesting image to server
  2019/09/30 15:41:52 Pixels: &amp;{[164 164 164 164 164 164 164 164 164 164 164 164 164 164 164
   164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 1
  64 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164
   164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 1
  64 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164
   164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 1
  64 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164
   164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 1
  64 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164
   164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 1
  64 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164
   164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 164] [128 128 128 128 128 128
   128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 1
  28 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128
   128 128 128 128 128 128 128 128 128 128 128 128 128] [128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128] 16 8 YCbCrSubsampleRatio420 (0,0)-(1,1)}
  </code></pre>
  
  <p>I was expecting that the client would print:
  Pixels: &amp;{[164 16] 2 (0,0)-(1,1)} 
  as well. 
  Is it just a difference in the printing format, or is the image not-correctly decoded?</p>