size_get.c
744 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
38
39
40
41
42
43
#include <search.h>
#include <string.h>
#include <sys/types.h>
#include "http/message.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)
{
HttpMessage message = (HttpMessage)response;
size = 0;
size += strlen(message->version) + 1;
size += 4; // for status
size += strlen(response->reason) + 2;
twalk(message->header, addHeaderSize);
size += 2;
if (HTTP_MESSAGE_BUFFERED == message->type) {
size += message->nbody;
}
return size;
}
// vim: set ts=4 sw=4: