I have a couple questions about what is expected when it comes to the respond to client part of the code. My confusion arises when it comes to the part where we have to write out the bytes of the file. In the dynamic part of the code the variable size is referring to the size of the entire file (if I'm understanding correctly). The variable body points to the contents of the file in memory as loaded by load(). The code then calculates length which I believe is the size of the file minus the headers, thus describing the size of just the files bytes (the ones we have to write in the response). Then when the actual write comes, we get this:
write(cfd, body, size)
Doesn't this write the entire file in the response, including the headers? Is that what we want to do? I'm just not clear whether we're supposed to write the all the bytes in the file, or just the bytes after the header ie: the content. Is the only reason for the math involving the variables haystack, needle and size to extract the length for the "Content-Length" part of the response?
If anyone could offer some clarification on this I would appreciate it! As is stands I'm just going to experiment and assume that if my server is displaying the html and jpg pages then it's working as intended. Thanks in advance!