0

This is the very last thing I seem to have to fix here. Telnet and GDB are returning no errors, but when I try to use my server.c in Chrome, I don't get the requested page. Instead, I get an error on Chrome that says, "No data received; ERR_EMPTY_RESPONSE; Unable to load the webpage because the server sent no data."

I have no idea what could be causing this, so I don't know what to include as far as code. Telnet is telling me that the Content-Length is -1, if that helps at all.

I've seen few others with this problem. Any solutions?

EDIT - respond to client

// TODO: respond to client
        printf("HTTP/1.1 200 OK\r\n");
        printf("Connection: close\r\n");
        printf("Content-Length: %i\r\n", load());
        printf("Content-Type: %s\r\n", lookup(extension));
  • Please execute "./server -p 8080 public" from within your own ~/Dropbox/pset6 directory in one terminal window. Then in a second window type "telnet #.#.#.# 8080" (#s are terminal's ip). Lastly, in telnet, type "GET /hello.html HTTP/1.1" and hit return twice. Edit your question above and paste the contents of the telnet window, so we can see what you're dealing with, please :) . – Sam Gerber Oct 21 '15 at 18:08
  • Telnet is telling me "Connection close by foreign host," but the other terminal window running the server is showing, "HTTP/1.1 200 OK, Connection: close, Content-Length: -1, Content-Type: text/html, HTTP/1.1 200 OK." Only the section "HTTP/1.1 200 OK" is in green text. The rest is in white. – Chris Oct 21 '15 at 18:28
  • Sorry, one more question. What about if you do the same thing for "/hello.php" and "nosuchfile.html" as well, please, to see if server.c is making the correct response for dynamic content and error messages? – Sam Gerber Oct 21 '15 at 18:56
  • Did you implement this TODO block: // TODO: respond to client? It was on line 241 of the original distribution code. – Sam Gerber Oct 21 '15 at 21:01
  • "hello.php" does actually spit out html code in Telnet. On Chrome, it displays "hello," then a table that displays an error, but that looks like a result of no name being put into "hello.php". "nosuchfile.html" gives me a 404, as we would expect. "hello.html" and "cat.html" seem to be the big issues, here. – Chris Oct 22 '15 at 4:49
2

Try mimicking what the distribution code used to generate the responses for the error messages and dynamic content:

if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0)
{
     continue;
}

// respond with Connection header
if (dprintf(cfd, "Connection: close\r\n") < 0)
{
    return false;
}

// respond with Content-Length header
if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0)
{
    return false;
}

// respond with Content-Type header
if (dprintf(cfd, "Content-Type: text/html\r\n") < 0)
{
    return false;
}

// respond with CRLF
if (dprintf(cfd, "\r\n") < 0)
{
    return false;
}

if (write(cfd, body, size) == -1)
{
     continue;
}

You'll have to update the content-type to be dynamic, reflecting the variable type.

| improve this answer | |
  • I updated length in respond with Content-length header and respond with message-body to load(), but clang is giving me an error that content is undeclared. Should I be using a different variable here? – Chris Oct 22 '15 at 5:17
  • Oh... it's undeclared here because it's hidden in side the error function... – Chris Oct 22 '15 at 5:19
  • Yeah, sorry, try the new one as above, it's copied from the dynamic response. I think they call it body instead of content. It's the global variable that is handled by the load function. – Sam Gerber Oct 22 '15 at 5:22
  • Good news: Telnet is now showing me Content-Length for cat.html is 156 instead of -1. Bad news: Chrome is telling me "ERR_CONNECTION_REFUSED" when I try it from there. – Chris Oct 22 '15 at 5:27
  • 1
    OH WAIT! I changed a typo, and we have a cat now! – Chris Oct 22 '15 at 5:30

You must log in to answer this question.

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