You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
772 B

#pragma once
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#ifdef NO_GC
#include <gc.h>
#define malloc(n) GC_malloc(n)
#else
#include <stdlib.h>
#endif
typedef struct {
char *method;
char *path;
char protocol[16];
} ReqHeader;
ReqHeader readReqHeader(int client) {
char* buf = malloc(1024);
//read(client, buf, 1024);
recv(client, buf, 1024, 0);
ReqHeader header;
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");
}
return header;
}