new homepage and remove warnings
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "main.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "client/client.h"
|
||||
#include "utils/colors.h"
|
||||
|
||||
@@ -21,7 +21,7 @@ http_t *http_parse(char *request_str, int sockfd) {
|
||||
if (pch == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
printf("[http] method: %s\n", pch);
|
||||
printf("[client::http] method: %s\n", pch);
|
||||
http_parse_method(request, pch);
|
||||
|
||||
/* Parse location */
|
||||
@@ -29,24 +29,24 @@ http_t *http_parse(char *request_str, int sockfd) {
|
||||
if (pch == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
printf("[http] location: %s\n", pch);
|
||||
printf("[client::http] location: %s\n", pch);
|
||||
strncpy(request->location, pch, LOCATION_LEN);
|
||||
|
||||
/* Parse location path */
|
||||
/* TODO: Prevent Path Traversal */
|
||||
if (strcmp(request->location, "/") == 0) {
|
||||
snprintf(request->location_path, LOCATION_LEN, "%s/index.html", WWW);
|
||||
snprintf(request->location_path, LOCATION_PATH_LEN, "%s/index.html", WWW);
|
||||
} else {
|
||||
snprintf(request->location_path, LOCATION_LEN, "%s%s", WWW, request->location);
|
||||
snprintf(request->location_path, LOCATION_PATH_LEN, "%s%s", WWW, request->location);
|
||||
}
|
||||
fprintf(stdout, "[http] location path: %s\n", request->location_path);
|
||||
fprintf(stdout, "[client::http] location path: %s\n", request->location_path);
|
||||
|
||||
/* Parse HTTP version */
|
||||
pch = strtok(NULL, " \r\n");
|
||||
if (pch == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
printf("[http] version: %s\n", pch);
|
||||
printf("[client::http] version: %s\n", pch);
|
||||
strncpy(request->http_version, pch, HTTP_VERSION_LEN);
|
||||
|
||||
/* Parse other stuff... */
|
||||
@@ -96,7 +96,7 @@ void http_send_response(http_t *request) {
|
||||
fread(file_data, 1, content_length, file);
|
||||
fclose(file);
|
||||
|
||||
char response_header[1024];
|
||||
char response_header[2048];
|
||||
snprintf(response_header, sizeof response_header,
|
||||
"%s 200 OK\r\n"
|
||||
"Content-Type: %s\r\n"
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#include "main.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "server/server.h"
|
||||
#include "utils/colors.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
fprintf(stdout, BOLD GREEN "[server] Running cws on http://localhost:%s...\n" RESET, "3030");
|
||||
const char *default_port = "3030";
|
||||
|
||||
int ret = start_server(NULL, "3030");
|
||||
fprintf(stdout, BOLD GREEN "[server] Running cws on http://localhost:%s...\n" RESET, default_port);
|
||||
|
||||
int ret = start_server(NULL, default_port);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, BOLD RED "Unable to start web server\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user