title: Is it possible to read only first N bytes from the HTTP server using Linux command?
body: <p>Here is the question.</p>
  
  <p>Given the url <em><a href="http://www.example.com" rel="noreferrer">http://www.example.com</a></em>, can we read the first N bytes out of the page?</p>
  
  <ul>
  <li>using <strong>wget</strong>, we can download the whole page.</li>
  <li><p>using <strong>curl</strong>, there is -r, 0-499 specifies the first 500 bytes. Seems solve the problem.</p>
  
  <blockquote>
    <p><em>You should also be aware that many HTTP/1.1 servers do not have this feature enabled, so that when you attempt to get a range, you'll instead get the whole document.</em></p>
  </blockquote></li>
  <li><p>using <strong>urlib</strong> in python. similar question <a href="https://stackoverflow.com/questions/2986392/what-is-the-best-way-to-open-a-url-and-get-up-to-x-bytes-in-python">here</a>, but according to Konstantin's comment, is that really true?</p>
  
  <blockquote>
    <p><em>Last time I tried this technique it failed because it was actually impossible to read from the HTTP server only specified amount of data, i.e. you implicitly read all HTTP response and only then read first N bytes out of it. So at the end you ended up downloading the whole 1Gb malicious response.</em></p>
  </blockquote></li>
  </ul>
  
  <p>So the problem is that how can we read the first N bytes from the HTTP server in practice?</p>
  
  <p>Regards &amp; Thanks</p>