I am working on a network client and one of its features is download files over HTTP server, i.e. www.abc-xyz.com/files.exe. The program downloads some files successfully, but it fails to download some files. For some reason, it download the all files, but some files are unvalid in terms of CRC.
I understand that the server initially sends information about a file including its size and type (Content-Type). However, for some reason files that have bad CRC seem to miss the beginning chunk of data. In other words, the program does the file, but the first twenty bytes might contain bad CRC. Here is the algorithm of the design.
- Send request (GET)
- Call WSARecv
- On first incoming data, analyze data and determine file size.
- Analyze data and save any valid data that server might have including with file information.
- Call WSARecv
- Continue calling WSARecv and appending new data until size of data equals the size that the server sent.
I would like to know is it possible that the server sends out the data before it sends out information about the data such as size? With the algorithm above, the program can download some file, but fails other files in terms of CRC. I cannot understand how that is possible because the size of the file is correct most of the time, but even so the files have bad CRC. Another interesting fact is that the bad CRC always occurs at the beginning such as the first 20 bytes.