0

enter image description hereenter image description hereenter image description hereenter image description here

As shown, I've set all files (hello.html, cat.html, cat.jpg) to be readable. But when I try to go onto those locations on my local web-browsers what came up was a blank page for hello.html and this (as shown in picture) for cat.html. I think the problem with the code is problably the [response to client] part for static content: here is the code...

            // load file
            ssize_t length = load();
            // printf("Length is: %i\n", length);
            if (length == -1)
            {
                error(500);
                continue;
            }

            // TODO: 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;
            }
        }
5
  • You said, "As shown, I've set all files (hello.html, cat.html, cat.jpg) to be readable." Where did you show this?
    – Sam Gerber
    Sep 28 '15 at 3:22
  • I've added a picture just for your reference. But if the files are not readable the browser would display 403 forbidden.
    – Jack Lee
    Sep 28 '15 at 7:02
  • Seems OK to me. Can you show what your Javascript console shows (the red cross in your last image) ?
    – Mustaghees
    Sep 28 '15 at 14:41
  • Just added as shown above, is that what you meant?
    – Jack Lee
    Sep 28 '15 at 18:12
  • Any solution found for this? I have exactly the same problem. My server works when requesting a page using telnet and returns the correct HTML but when using a browser I get no content and the ERR_CONTENT_LENGTH_MISMATCH. I checked with the staff's implementation and the content-length given by my server matches theirs in telnet.
    – Dom Myers
    Sep 30 '15 at 21:33
1

Are you missing another CRLF maybe?

Try this:

if (dprintf(cfd, "\r\n") < 0)
{
    continue;
}

After the last dprintf(), and before write().

You must log in to answer this question.

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