#include "linkedlist.h"
#include <stddef.h>
Go to the source code of this file.
|
typedef enum methods | methods |
|
typedef struct request | request |
|
|
enum | methods { GET
, POST
, HEAD
} |
|
◆ create_request()
int create_request |
( |
char | request_buffer[], |
|
|
request * | req ) |
given a request buffer, populate the request struct
- Parameters
-
request_buffer | the buffer to use as a source |
req | the request struct to populate |
- Returns
- -1 if there was an error, 0 if there wasn't
This function is the first step to create a request out of a raw buffer that comes from the socket.
◆ get_header()
ll_node * get_header |
( |
char * | header_line, |
|
|
char ** | header_save ) |
- Parameters
-
header_line | a header line in the format "Key: Val" |
header_save | a save pointer to track the header lines |
- Returns
- an ll_node pointer representing this header
◆ get_headers()
int get_headers |
( |
char | headers_buffer[], |
|
|
request * | req ) |
- Parameters
-
headers_buffer | the entire buffer of headers, deliminated by "\r\n" |
req | the request struct that these headers will be added to |
- Returns
- -1 if there was some error, 0 if no error was encountered
Given the first header line, the headers root, and the line save pointer, add each header to the headers linked list
◆ get_request_line()
int get_request_line |
( |
char ** | headers_buffer, |
|
|
char | request_buffer[], |
|
|
request * | req ) |
- Parameters
-
headers_buffer | a save pointer that will point to the beginning of the headers. |
request_buffer | the buffer containing the entire request |
req | the request struct that will will receive the request line properties |
Given an http request line, break out the method & uri, then add it to the request struct. Use headers_buffer as a save pointer. This will make it so it points to the headers, as they come right after the first "\r\n".
◆ parse_route_from_request()
int parse_route_from_request |
( |
char | request[], |
|
|
char | buffer[], |
|
|
size_t | buf_size ) |
parse a route from a request
- Parameters
-
request | the request line of the HTTP request |
buffer | the destination buffer to put the route |
buf_size | the size (in bytes) of the buffer |
- Returns
- number of bytes written. 0 if the route is bigger than the buffer
This function will copy the entire route found in the first line of a request. Beginning at "/" and ending at the first whitespace encountered. It is the responsibility of the consumer to null terminate the buffer.