clean up ecore-con server example: HTTP requires a seperator (\r\n in this case) following each header line and a double separator between headers and body. additionally, content-length must be EXACTLY the length of the body, and must not include trailing garbage.

snprintf use here is incorrect due to inconsistent behavior of snprintf, so we can lazily fall back to strlen since this is just a simple example


SVN revision: 61421
This commit is contained in:
Mike Blumenkrantz 2011-07-16 08:01:19 +00:00
parent 42cf875234
commit 300a32728b
1 changed files with 4 additions and 6 deletions

View File

@ -14,11 +14,10 @@ static const char response_template[] =
"Server: Ecore_Con custom server\r\n"
"Content-Length: %zd\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
"Set-Cookie: MYCOOKIE=1; path=/; expires=%s"
"Set-Cookie: MYCOOKIE=1; path=/; expires=%s\r\n"
"Set-Cookie: SESSIONCOOKIE=1; path=/\r\n"
"\r\n"
"%s"
"\r\n\r\n";
"%s";
struct _Client {
int sdata;
@ -31,7 +30,6 @@ _add(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev)
client->sdata = 0;
static char buf[4096];
char welcome[] = "Welcome to Ecore_Con server!";
int nbytes;
time_t t;
printf("Client with ip %s, port %d, connected = %d!\n",
@ -43,9 +41,9 @@ _add(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev)
t = time(NULL);
t += 60 * 60 * 24;
nbytes = snprintf(buf, sizeof(buf), response_template, sizeof(welcome), ctime(&t), welcome);
snprintf(buf, sizeof(buf), response_template, sizeof(welcome) - 1, ctime(&t), welcome);
ecore_con_client_send(ev->client, buf, nbytes);
ecore_con_client_send(ev->client, buf, strlen(buf));
ecore_con_client_flush(ev->client);