From 0408eb269ced89a2dce71ef9320000f9be0990c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E8=BE=9C=E7=9A=84=E7=86=8A=E6=9C=AC=E7=86=8A?= <10804640+innocent-kumamoto@user.noreply.gitee.com> Date: Wed, 15 May 2024 09:48:45 +0800 Subject: [PATCH] delete get request support --- src/simplehttpd.c | 91 ++--------------------------------------------- 1 file changed, 3 insertions(+), 88 deletions(-) diff --git a/src/simplehttpd.c b/src/simplehttpd.c index 8b9f337..d4b943d 100644 --- a/src/simplehttpd.c +++ b/src/simplehttpd.c @@ -310,20 +310,6 @@ void post_process(int client, const char *path, const char *method, const char * } } -void get_process(int client, const char *path, const char *method, const char *query_string) -{ - char buf[MAX_BUFFER_SIZE]; - int numchars = 1; - buf[0] = 'A'; - buf[1] = '\0'; - while ((numchars > 0) && strcmp("\n", buf)) - { - numchars = get_line(client, buf, sizeof(buf)); - // Todo... - } - response_ok(client); -} - void *accept_request(void *arg) { int client = *(int *)arg; @@ -346,7 +332,7 @@ void *accept_request(void *arg) } method[i] = '\0'; - if (strcasecmp(method, "GET") && strcasecmp(method, "POST")) + if (strcasecmp(method, "POST")) { unimplemented(client); close(client); @@ -364,84 +350,13 @@ void *accept_request(void *arg) j++; } url[i] = '\0'; - - if (strcasecmp(method, "GET") == 0) - { - query_string = url; - while ((*query_string != '?') && (*query_string != '\0')) - query_string++; - - if (*query_string == '?') - { - *query_string = '\0'; - query_string++; - } - } - - if (strcasecmp(method, "POST") == 0) - { - post_process(client, url, method, query_string); - } - else - { - get_process(client, url, method, query_string); - } + + post_process(client, url, method, query_string); close(client); return NULL; } -void cat(int client, FILE *resource) -{ - char buf[MAX_BUFFER_SIZE]; - - fgets(buf, sizeof(buf), resource); - while (!feof(resource)) - { - send(client, buf, strlen(buf), MSG_NOSIGNAL); - fgets(buf, sizeof(buf), resource); - } -} - -void headers(int client, const char *filename) -{ - char buf[MAX_BUFFER_SIZE]; - (void)filename; - - strcpy(buf, "HTTP/1.0 200 OK\r\n"); - send(client, buf, strlen(buf), MSG_NOSIGNAL); - - strcpy(buf, SERVER_STRING); - send(client, buf, strlen(buf), MSG_NOSIGNAL); - sprintf(buf, "Content-Type: text/html\r\n"); - send(client, buf, strlen(buf), MSG_NOSIGNAL); - strcpy(buf, "\r\n"); - send(client, buf, strlen(buf), MSG_NOSIGNAL); -} - -void serve_file(int client, const char *filename) -{ - FILE *resource = NULL; - int numchars = 1; - char buf[MAX_BUFFER_SIZE]; - - buf[0] = 'A'; - buf[1] = '\0'; - while ((numchars > 0) && strcmp("\n", buf)) - numchars = get_line(client, buf, sizeof(buf)); - - resource = fopen(filename, "r"); - if (resource == NULL) - not_found(client); - else - { - headers(client, filename); - - cat(client, resource); - } - fclose(resource); -} - int RegisterPostProcessDoneCallback(PostProcessDoneCallback callback) { post_process_done_callback = callback; -- Gitee