1

The request headers and response headers in the command line and in Chrome are all fine, but cat.jpg, cat.html, and hello.html do not display anything in Chrome.

In the command line, cat.html and hello.html print out the html, and cat.jpg spits out a bunch of stuff in the command line as if it would open. However, these files do nothing inside of Chrome.

When I try to open the file in Chrome with the developer tools open, I can see the request and response headers are fine.

I only added a few lines to the pset's code to implement static content:

// respond to client
if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0)
{
    continue;
}
if (dprintf(cfd, "Connection: close\r\n") < 0)
{
    continue;
}
if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0)
{
     continue;
}
if (dprintf(cfd, "Content-Type: %s\r\n", type) < 0)
{
     continue;
}
if (write(cfd, body, length) == -1)
{
     continue;
}

The response header has the HTTP, Connection, Content-Length, and Content-Type printed out, but the actual file does not seem to be opening.

2

per the specs:

Complete the implementation of support for static content in such a way that, after loading a file into memory via load, main responds to a browser with these lines

HTTP/1.1 200 OK 
Connection: close 
Content-Length: %i 
Content-Type: %s

each of which is terminated with CRLF (i.e., \r\n), which are followed after a single blank line (i.e., an additional CRLF) by the bytes of the file itself, whereby %i represents the file’s size in bytes and %s represents the file’s MIME type.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .