开发者

http response to GET request - working in FF not Chromium

For fun I'm trying to write a very simple server in C.

When I send this response to Firefox it prints out the body "hello, world" but with Chromium it gives me a Error 100 (net::ERR_CONNECTION_CLOSED): Unknown error.

This, I believe, is the relevant code:

char *response = "HTTP/1.0 200 OK\r\nVary: Accept-Encoding, Accept-Language\r\nConnection: Close\r\nContent-Type: text/p开发者_运维百科lain\r\nContent-Length:20\r\n\r\nhello, world";
    if(send(new_fd, response, strlen(response), 0) == strlen(response)) {
        printf("sent\n");   
    };

    close(new_fd);

What am I missing?

Thanks!


Content-Length seems to be 12, not 20.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4:

When a Content-Length is given in a message where a message-body is allowed, its field value MUST exactly match the number of OCTETs in the message-body. HTTP/1.1 user agents MUST notify the user when an invalid length is received and detected

Doesn't that mean FF violates specs? (Well, you are using HTTP/1.0, so maybe not.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜