This commit adds tests for a request and the implementation. The first line of a request should now be decoded correctly
53 lines
1 KiB
C
53 lines
1 KiB
C
#ifndef REQUEST_H
|
|
#define REQUEST_H
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "readline.h"
|
|
#include <netinet/in.h>
|
|
|
|
|
|
/*
|
|
* 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
|
|
float version;
|
|
char *method;
|
|
char *protocol;
|
|
char *host;
|
|
char *path;
|
|
HeaderList *headers;
|
|
char *queryString;
|
|
char *body;
|
|
} Request;
|
|
|
|
Header* newHeader();
|
|
Request* newRequest();
|
|
void requestFirstLine( Request *req, char line[] );
|
|
Request* newRequestFromSocket(int socket);
|
|
void* addHeader(Request *req, char line[]);
|
|
void* interpretLine1(Request *req, char line[]);
|
|
|
|
|
|
|
|
#endif /* ifndef REQUEST_H */
|