-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.c
34 lines (33 loc) · 840 Bytes
/
http.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "http.h"
#include <stdio.h>
#include <stdlib.h>
void AddHeader(HttpHeaders *headers, char *name, char *value) {
HttpHeader *header = malloc(sizeof(HttpHeader));
header->name = name;
header->value = value;
header->next = NULL;
if (headers->tail == NULL) {
headers->head = header;
headers->tail = header;
} else {
headers->tail->next = header;
headers->tail = header;
}
}
void PrintHeaders(HttpHeaders *headers) {
HttpHeader *header = headers->head;
while (header != NULL) {
printf("%s: %s\n", header->name, header->value);
header = header->next;
}
}
void CleanHeaders(HttpHeaders *headers) {
HttpHeader *header = headers->head;
while (header != NULL) {
free(header->name);
free(header->value);
header = header->next;
}
headers->head = NULL;
headers->tail = NULL;
}