mirror of
https://github.com/fumiama/simple-http-server.git
synced 2026-06-05 00:30:23 +08:00
add unimplemented
This commit is contained in:
26
server.c
26
server.c
@@ -99,6 +99,12 @@ static void accept_request(void *cli) {
|
|||||||
cgi = 1;
|
cgi = 1;
|
||||||
method_type = POST;
|
method_type = POST;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
unimplemented(client);
|
||||||
|
discard(client);
|
||||||
|
close(client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
skipspace(buf, j, numchars - 1);
|
skipspace(buf, j, numchars - 1);
|
||||||
path = buf + j + 1;
|
path = buf + j + 1;
|
||||||
@@ -121,11 +127,13 @@ static void accept_request(void *cli) {
|
|||||||
path[0] = '.'; path[1] = '/';
|
path[0] = '.'; path[1] = '/';
|
||||||
|
|
||||||
printf("[%s] <%s> (%s) = ", getmethod(method_type), path, query_string);
|
printf("[%s] <%s> (%s) = ", getmethod(method_type), path, query_string);
|
||||||
// 花括号不可省略
|
do {
|
||||||
if(stat(path, &st) == -1) {
|
// 花括号不可省略
|
||||||
discard(client);
|
if(stat(path, &st) == -1) {
|
||||||
not_found(client);
|
not_found(client);
|
||||||
} else {
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
int pathlen = strlen(path) + 1;
|
int pathlen = strlen(path) + 1;
|
||||||
char path_stack[pathlen + 11]; // 11 is for possible /index.html
|
char path_stack[pathlen + 11]; // 11 is for possible /index.html
|
||||||
memcpy(path_stack, path, pathlen);
|
memcpy(path_stack, path, pathlen);
|
||||||
@@ -142,10 +150,8 @@ static void accept_request(void *cli) {
|
|||||||
strcat(path, "/index.html");
|
strcat(path, "/index.html");
|
||||||
// 花括号不可省略
|
// 花括号不可省略
|
||||||
if(stat(path, &st) == -1) {
|
if(stat(path, &st) == -1) {
|
||||||
discard(client);
|
|
||||||
not_found(client);
|
not_found(client);
|
||||||
close(client);
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int content_length = 0;
|
int content_length = 0;
|
||||||
@@ -166,7 +172,9 @@ static void accept_request(void *cli) {
|
|||||||
request.query_string = query_string;
|
request.query_string = query_string;
|
||||||
execute_cgi(client, content_length, &request);
|
execute_cgi(client, content_length, &request);
|
||||||
}
|
}
|
||||||
}
|
} while(0);
|
||||||
|
|
||||||
|
discard(client);
|
||||||
close(client);
|
close(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user