1
0
mirror of https://github.com/lxsang/ant-http synced 2024-07-01 12:59:47 +02:00

fix cookie error on POST message

This commit is contained in:
root 2016-11-01 02:11:48 +00:00
parent 5ebe581ea3
commit 355bda010d

View File

@ -39,22 +39,26 @@ dictionary decode_request(int client,const char* method,const char* query)
dictionary request = NULL; dictionary request = NULL;
dictionary cookie = NULL; dictionary cookie = NULL;
char* line; char* line;
char * token;
if(strcmp(method,"GET") == 0) if(strcmp(method,"GET") == 0)
{ {
while((line = read_line(client)) && strcmp("\r\n",line)) while((line = read_line(client)) && strcmp("\r\n",line))
{ {
if(!cookie) cookie = decode_cookie(line); token = strsep(&line,":");
trim(token,' ');
if(token != NULL &&strcasecmp(token,"Cookie") == 0)
if(!cookie) cookie = decode_cookie(line);
} }
request = decode_url_request(query); request = decode_url_request(query);
} }
else else
{ {
char * token;
char* ctype = NULL; char* ctype = NULL;
int clen = -1; int clen = -1;
line = read_line(client); line = read_line(client);
while ((strlen(line) > 0) && strcmp("\r\n",line)) while (line && strcmp("\r\n",line))
{ {
//printf("%s\n",line);
token = strsep(&line,":"); token = strsep(&line,":");
trim(token,' '); trim(token,' ');
if(token != NULL &&strcasecmp(token,"Content-Type") == 0) if(token != NULL &&strcasecmp(token,"Content-Type") == 0)
@ -69,7 +73,7 @@ dictionary decode_request(int client,const char* method,const char* query)
trim(token,' '); trim(token,' ');
clen = atoi(token); clen = atoi(token);
} }
else else if(token != NULL &&strcasecmp(token,"Cookie") == 0)
{ {
if(!cookie) cookie = decode_cookie(line); if(!cookie) cookie = decode_cookie(line);
} }
@ -128,22 +132,18 @@ dictionary decode_cookie(const char* line)
char *token,*token1; char *token,*token1;
char *cpstr = strdup(line); char *cpstr = strdup(line);
dictionary dic = NULL; dictionary dic = NULL;
token = strsep(&cpstr,":"); while((token = strsep(&cpstr,";")))
trim(token,' ');
if(token != NULL &&strcasecmp(token,"Cookie") == 0)
{ {
while((token = strsep(&cpstr,";"))) token1 = strsep(&token,"=");
if(token1)
{ {
token1 = strsep(&token,"="); if(dic == NULL)
if(token1) dic = dict();
{ LOG("Found cookie : %s = %s\n",token1,token);
if(dic == NULL) dput(dic,token1,token);
dic = dict();
LOG("Found cookie : %s = %s\n",token1,token);
dput(dic,token1,token);
}
} }
} }
//}
return dic; return dic;
//free(cpstr); //free(cpstr);
} }