mirror of
https://github.com/lxsang/ant-http
synced 2024-12-26 16:58:22 +01:00
minor fix
This commit is contained in:
parent
e07e91ac9c
commit
8b7ce33944
BIN
._Makefile
BIN
._Makefile
Binary file not shown.
@ -38,6 +38,7 @@ dictionary decode_request(int client,const char* method,const char* query)
|
||||
{
|
||||
dictionary request = NULL;
|
||||
dictionary cookie = NULL;
|
||||
dictionary xheader = dict();
|
||||
char* line;
|
||||
char * token;
|
||||
if(strcmp(method,"GET") == 0)
|
||||
@ -47,8 +48,12 @@ dictionary decode_request(int client,const char* method,const char* query)
|
||||
char* ws_key = NULL;
|
||||
while((line = read_line(client)) && strcmp("\r\n",line))
|
||||
{
|
||||
trim(line, '\n');
|
||||
trim(line, '\r');
|
||||
token = strsep(&line,":");
|
||||
trim(token,' ');
|
||||
trim(line,' ');
|
||||
dput(xheader,token,line);
|
||||
if(token != NULL &&strcasecmp(token,"Cookie") == 0)
|
||||
{
|
||||
if(!cookie) cookie = decode_cookie(line);
|
||||
@ -57,16 +62,12 @@ dictionary decode_request(int client,const char* method,const char* query)
|
||||
{
|
||||
// verify that the connection is upgrade to websocket
|
||||
trim(line, ' ');
|
||||
trim(line, '\n');
|
||||
trim(line, '\r');
|
||||
if(line != NULL && strcasecmp(line,"websocket") == 0)
|
||||
ws = 1;
|
||||
} else if(token != NULL && strcasecmp(token,"Sec-WebSocket-Key") == 0)
|
||||
{
|
||||
// get the key from the client
|
||||
trim(line, ' ');
|
||||
trim(line, '\n');
|
||||
trim(line, '\r');
|
||||
ws_key = strdup(line);
|
||||
}
|
||||
}
|
||||
@ -90,14 +91,16 @@ dictionary decode_request(int client,const char* method,const char* query)
|
||||
while (line && strcmp("\r\n",line))
|
||||
{
|
||||
//printf("%s\n",line);
|
||||
trim(line, '\n');
|
||||
trim(line, '\r');
|
||||
token = strsep(&line,":");
|
||||
trim(token,' ');
|
||||
trim(line, ' ');
|
||||
dput(xheader,token,line);
|
||||
if(token != NULL &&strcasecmp(token,"Content-Type") == 0)
|
||||
{
|
||||
ctype = strsep(&line,":");
|
||||
trim(ctype,' ');
|
||||
trim(ctype,'\n');
|
||||
trim(ctype,'\r');
|
||||
} else if(token != NULL &&strcasecmp(token,"Content-Length") == 0)
|
||||
{
|
||||
token = strsep(&line,":");
|
||||
@ -140,10 +143,11 @@ dictionary decode_request(int client,const char* method,const char* query)
|
||||
}
|
||||
}
|
||||
//if(cookie->key == NULL) {free(cookie);cookie= NULL;}
|
||||
if(cookie && !request)
|
||||
if(!request)
|
||||
request = dict();
|
||||
|
||||
dput(request,"cookie",cookie);
|
||||
dput(request,"__xheader__",xheader);
|
||||
return request;
|
||||
}
|
||||
void __px(const char* data,int size)
|
||||
|
@ -30,12 +30,10 @@ sqldb getdb()
|
||||
return getdb(__plugin__.name);
|
||||
}
|
||||
#endif
|
||||
void header_base(int client)
|
||||
void set_status(int client,int code,const char* msg)
|
||||
{
|
||||
|
||||
response(client, "HTTP/1.0 200 OK");
|
||||
response(client, __s("HTTP/1.0 %d %s", code, msg));
|
||||
response(client, __s("Server: %s ", SERVER_NAME));
|
||||
|
||||
}
|
||||
void redirect(int client,const char*path)
|
||||
{
|
||||
@ -60,7 +58,7 @@ void textstream(int client)
|
||||
}
|
||||
void octstream(int client, char* name)
|
||||
{
|
||||
header_base(client);
|
||||
set_status(client,200,"OK");
|
||||
__t(client,"Content-Type: application/octet-stream");
|
||||
__t(client,"Content-Disposition: attachment; filename=\"%s\"", name);
|
||||
response(client,"");
|
||||
@ -72,7 +70,7 @@ void jpeg(int client)
|
||||
}
|
||||
void header(int client, const char* type)
|
||||
{
|
||||
header_base(client);
|
||||
set_status(client,200,"OK");
|
||||
__t(client,"Content-Type: %s",type);
|
||||
response(client,"");
|
||||
}
|
||||
@ -240,7 +238,7 @@ int upload(const char* tmp, const char* path)
|
||||
}
|
||||
void set_cookie(int client,const char* type, dictionary dic)
|
||||
{
|
||||
header_base(client);
|
||||
set_status(client,200,"OK");
|
||||
__t(client,"Content-Type: %s",type);
|
||||
association assoc;
|
||||
for_each_assoc(assoc,dic){
|
||||
@ -250,7 +248,7 @@ void set_cookie(int client,const char* type, dictionary dic)
|
||||
}
|
||||
void clear_cookie(int client, dictionary dic)
|
||||
{
|
||||
header_base(client);
|
||||
set_status(client,200,"OK");
|
||||
__t(client,"Content-Type: text/html; charset=utf-8");
|
||||
association assoc;
|
||||
for_each_assoc(assoc,dic){
|
||||
|
@ -36,7 +36,6 @@ extern plugin_header __plugin__;
|
||||
extern call __init__;
|
||||
|
||||
int response(int, const char*);
|
||||
void header_base(int);
|
||||
void header(int,const char*);
|
||||
void redirect(int,const char*);
|
||||
void html(int);
|
||||
@ -59,6 +58,7 @@ sqldb getdb();
|
||||
sqldb __getdb(char *name);
|
||||
#endif
|
||||
void set_cookie(int, const char*,dictionary);
|
||||
void set_status(int,int,const char*);
|
||||
void clear_cookie(int, dictionary);
|
||||
/*Default function for plugin*/
|
||||
void handler(int, const char*,const char*,dictionary);
|
||||
|
Loading…
Reference in New Issue
Block a user