I have made a start

I have done some work on opening a socket and waiting for a connection.
This can be read line by line and I have started a request struct that
it will accept.

Also started on some docs. Not much is yet working. I am going to start
learning µnit for unit tests:

https://nemequ.github.io/munit/
This commit is contained in:
Jonathan Hodgson 2021-12-27 21:43:11 +00:00
parent 4e17e706fa
commit f48a110429
15 changed files with 599 additions and 1 deletions

53
src/request.h Normal file
View file

@ -0,0 +1,53 @@
#ifndef REQUEST_H
#define REQUEST_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "readline.h"
#include <netinet/in.h>
typedef enum {HTTP,HTTPS} HTTPProtocol;
typedef enum {GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH} HTTPMethod;
/*
* A struct reperesenting an http header
*/
typedef struct {
char *name;
// The spec doesn't specify a max size for headers, but nginx doesn't accept headers bigger than 4096 so that's probably ok for us
char *value;
} Header;
/*
* A linked list wrapper around the headers
*/
typedef struct HeaderList HeaderList;
struct HeaderList {
Header header;
HeaderList *next;
};
/*
* A struct reperesenting an http request
*/
typedef struct {
// Common versions are: 0.9, 1.0, 1.1, 2.0
double version;
HTTPMethod method;
HTTPProtocol protocol;
char *host;
char *path;
HeaderList *headers;
char *queryString;
char *body;
} Request;
Header* newHeader();
Request* newRequest();
Request* newRequestFromSocket(int socket);
void* addHeader(Request *req);
#endif /* ifndef REQUEST_H */