Results 1 to 3 of 3
I'm writing a small webserver example and faced with some strange thing - headers in my server's output are not always interpreted as 'headers' across different browsers. I think that ...
- 07-19-2010 #1Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
[SOLVED] Writing webserver - how to correctly send headers?
I'm writing a small webserver example and faced with some strange thing - headers in my server's output are not always interpreted as 'headers' across different browsers. I think that I do something wrong, but don't know what it is. Then, my server's work:
1. When a client connects, it creates a new thread to handle its request. It pass a socket descriptor as is, and only child thread sends data to the socket and do it only once, at the end of his work.
and after it, for example, Firefox prints all of it as content on the page and only '200 OK HTTP/0.9' header is seen in LiveHTTPHeaders, but Konqueror works absolutely as I want - it sees headers and data separately. And what's the matter?Code:/* this is the output operation */ char *default_headers = "200 OK HTTP/1.0\ncontent-type:text/html\n\n"; char outbuf[40960]; char *databuf = NULL; /* ... There are malloc() call for 'databuf' and reading data from an html file into it ... */ // merge output strcat(outbuf, default_headers); strcat(outbuf, databuf); send(client_sock, outbuf, strlen(outbuf), 0);
- 07-19-2010 #2HTTP/1.1: ResponseAfter receiving and interpreting a request message, a server responds with an HTTP response message.
Response = Status-Line ; Section 6.1
*(( general-header ; Section 4.5
| response-header ; Section 6.2
| entity-header ) CRLF) ; Section 7.1
CRLF
[ message-body ] ; Section 7.2
6.1 Status-Line
The first line of a Response message is the Status-Line, consisting of the protocol version followed by a numeric status code and its associated textual phrase, with each element separated by SP characters. No CR or LF is allowed except in the final CRLF sequence.
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
It seems to imply that two cr/lf sequences should separate
the header from the content. I also believe the standard calls
for cr/lf, and not just newlines.
- 07-20-2010 #3Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
Thanks a lot


