Here is the question.
Given the url http://www.example.com, can we read the first N bytes out of the page?
- using wget, we can download the whole page.
using curl, there is -r, 0-499 specifies the first 500 bytes. Seems solve the problem.
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.
using urlib in python. similar question here, but according to Konstantin's comment, is that really true?
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.
So the problem is that how can we read the first N bytes from the HTTP server in practice?
Regards & Thanks
You can do it natively by the next curl command (no need to donwload whole document). According to culr man page:
It works for me even with Java web app that deployed to GigaSpaces.
You will have to get the whole web anyways, so you can get the web with curl and pipe it to head, for example.
Make a socket connection. Read the bytes you want. Close, and you're done.
I came here looking for a way to time the server's processing time, which I thought I could measure by telling curl to stop downloading after 1 byte or something.
For me, the better solution turned out to be to do a HEAD request, since this usually lets the server process the request as normal but does not return any response body:
or
should do
Also there are simpler utils with perhaps borader availability like
Or