From f61d3ce71f75bea1d5220d487cefca77bee78f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 5 Mar 2022 12:32:45 +0800 Subject: [PATCH] add unimplemented --- server.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/server.c b/server.c index f992102..088d46b 100644 --- a/server.c +++ b/server.c @@ -99,6 +99,12 @@ static void accept_request(void *cli) { cgi = 1; method_type = POST; } + else { + unimplemented(client); + discard(client); + close(client); + return; + } skipspace(buf, j, numchars - 1); path = buf + j + 1; @@ -121,11 +127,13 @@ static void accept_request(void *cli) { path[0] = '.'; path[1] = '/'; printf("[%s] <%s> (%s) = ", getmethod(method_type), path, query_string); - // 花括号不可省略 - if(stat(path, &st) == -1) { - discard(client); - not_found(client); - } else { + do { + // 花括号不可省略 + if(stat(path, &st) == -1) { + not_found(client); + break; + } + int pathlen = strlen(path) + 1; char path_stack[pathlen + 11]; // 11 is for possible /index.html memcpy(path_stack, path, pathlen); @@ -142,10 +150,8 @@ static void accept_request(void *cli) { strcat(path, "/index.html"); // 花括号不可省略 if(stat(path, &st) == -1) { - discard(client); not_found(client); - close(client); - return; + break; } } int content_length = 0; @@ -166,7 +172,9 @@ static void accept_request(void *cli) { request.query_string = query_string; execute_cgi(client, content_length, &request); } - } + } while(0); + + discard(client); close(client); }