title: Read remote file, and output to browser. Work with text and html. Don't work with images. NodeJs
body: <p>I have a little code:</p>
  
  <pre><code>var target = 'http://i.stack.imgur.com/5CXfX.png'; //For example, a .PNG image
  
  //Testing with text/html and text/plain and image/png
  res.setHeader( 'Content-Type', 'image/png' );//res is response of current request
  
  http.get( url.parse( target ), function( response ) {
  
     var data;
  
      response.on( 'data', function( chunk ) {
  
          if( !data ) data = chunk; else data += chunk;
  
      }).on('end', function() {
  
          res.send( data );
  
      });
  
  });
  </code></pre>
  
  <p>Which fetches data from <code>target</code>, and display it to the browser, depends on the <code>Content-Type</code> I set. As of now, it works very well in fetching document and display it as HTML or plain text. However, when changing the target to a direct image URL, and change <code>Content-Type</code> to corresponding type of file (such as <code>image/png</code> or <code>image/jpeg</code>), the image is broken. Even when I tried to download the image, its size (Content-Length) is just like the original size, but no program can open it because it is broken. I'm not quite sure how it works with text and html but not with images (even though the <code>Content-Type</code> has been set correctly)?</p>