size_get.c 744 Bytes
#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: