Locate the start of image data
The response of HTTP GET request contains both the HTTP status data and the image data. Only image data needs to be written in to the file and save. In case of JPEG, the image data starts with a marker of 2 byte.This can be followed by a 2 byte indicating the length of payload data. But in case of PNG file, it starts with an 8 byte signature. The possible HTTP end of response messages are located in the response buffer using strstr() function. The problem was fixed by carefully parsing the buffer and locating the end of response.
Handling related path and absolute path to download images on webpage
Webpages may use relative path or absolute path for images. The program has to identify which one is used and download the image to local disk. We have saved the relative path images by its original name and chopping the path in the address. The image is also downloaded to the same directory. The HTML file is also updated with the local file name. When the HTML file opens offline using any browser, the updated image address causes it to be open from the locally saved directory.
Problems Encountered in DNS Client
Big endian packing and unpacking of data
The initial problem we encountered was with the packing of information in the buffer before we send it out on the network. The information had to be packed in the big endian format. We initially started implementing by addressing individual bytes in the buffer. However it was increasingly difficult to individually represent them. Hence while packing the query, we used a data structure aligned in the big endian way.
While receiving the buffer, the contents had to be read in accordance to the big endianness. Here instead of structure based packing we have used pointer arithmetic to access the absolute location with respects to offsets. We had problems while accessing the response message with respect to the above mentioned logic which we had to overcome.
Decoding of compressed Response
We spent a considerable amount of time to decode the incoming response message. We had completely ignored to read the section on compression in the RFC. We later understood that we were unable to decode the response message properly because of the compression. We overcame by understanding the logic and implementing it as per the rfc's algorithm.
In some cases we need to handle the error based on the information in the code received in the response message. We were unable to analyse the failure until we coded this section to understand the error code returned.
Develop a Simple Web Client. Your web client doesn't need fancy GUIs. It accepts the URL from the command line and converts it to a simple HTTP GET request: GET
Do you see the images in the page displayed properly? If yes, congratulations! If no, why? You will receive a bonus of 20 pts by fixing the problem and displaying images correctly.