|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#ifdef NO_GC
|
|
|
|
|
#include <gc.h>
|
|
|
|
|
#define malloc(n) GC_malloc(n)
|
|
|
|
@ -19,13 +20,14 @@ ReqHeader readReqHeader(int client) {
|
|
|
|
|
char* buf = malloc(1024);
|
|
|
|
|
read(client, buf, 1024);
|
|
|
|
|
ReqHeader header;
|
|
|
|
|
header.method = malloc(1024);
|
|
|
|
|
header.path = malloc(1024);
|
|
|
|
|
char* tBuf = malloc(1024);
|
|
|
|
|
/*strcpy(header.method, strtok(buf, " "));
|
|
|
|
|
strcpy(header.path, strtok(NULL, " "));*/
|
|
|
|
|
sprintf(header.method, "%s", strtok_r(buf, " ", &tBuf));
|
|
|
|
|
sprintf(header.path, "%s", strtok_r(NULL, " ", &tBuf));
|
|
|
|
|
if (buf == NULL || !strcmp(buf, "")) {
|
|
|
|
|
errno = -1;
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
//header.method = malloc(1024);
|
|
|
|
|
//header.path = malloc(1024);
|
|
|
|
|
header.method = strtok(buf, " ");
|
|
|
|
|
header.path = strtok(NULL, " ");
|
|
|
|
|
if (header.path[1] == '\0') {
|
|
|
|
|
//strcpy(header.path, "/index.html");
|
|
|
|
|
sprintf(header.path, "/index.html");
|
|
|
|
|