-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.c
More file actions
74 lines (64 loc) · 1.76 KB
/
request.c
File metadata and controls
74 lines (64 loc) · 1.76 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "request.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Frees a request struct and every header node it owns.
* Calling with NULL is a no-op.
*/
void request_free(request *req) {
if (req == NULL) {
return;
}
free(req->method);
free(req->uri);
free(req->httpversion);
request_header *h = req->headers;
while (h != NULL) {
request_header *next = h->next;
free(h->key);
free(h->value);
free(h);
h = next;
}
free(req);
}
/*
* Returns the value of the "Expect" header, or NO_CONTINUE if absent.
* Previously crashed when headers was NULL.
*/
int find_expect(request **current_request) {
if (current_request == NULL || *current_request == NULL) {
return NO_CONTINUE;
}
request_header *header = (*current_request)->headers;
while (header != NULL) {
if (strcmp(header->key, "Expect") == 0) {
if (strcmp(header->value, "100-continue") == 0) {
return CONTINUE;
}
return NO_CONTINUE;
}
header = header->next;
}
return NO_CONTINUE;
}
/*
* Returns the value string of the "Content-Length" header, or NULL if absent.
* Previously crashed when headers was NULL, and returned a misleading
* non-NULL string on the not-found path which callers could not distinguish
* from a real value.
*/
char *find_content_len(request **current_request) {
if (current_request == NULL || *current_request == NULL) {
return NULL;
}
request_header *header = (*current_request)->headers;
while (header != NULL) {
if (strcmp(header->key, "Content-Length") == 0) {
return header->value;
}
header = header->next;
}
return NULL;
}