size_get.c
622 Bytes
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
#include <search.h>
#include <string.h>
#include <sys/types.h>
#include "http/response.h"
#include "http/header.h"
static size_t size;
static
inline
void
addHeaderSize(const void * node, const VISIT which, const int depth)
{
if (endorder == which || leaf == which) {
size += httpHeaderSizeGet(*(HttpHeader *)node) + 2;
}
}
size_t
httpResponseSizeGet(HttpResponse response)
{
size = 0;
size += strlen(response->version) + 1;
size += 4; // for status
size += strlen(response->reason) + 2;
twalk(response->header, addHeaderSize);
size += 2;
size += response->nbody;
return size;
}
// vim: set ts=4 sw=4: