开发者

http response to GET request - working in FF not Chromium

开发者 https://www.devze.com 2022-12-25 06:19 出处:网络
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_CLO

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

精彩评论

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