get_body.c 780 Bytes
#include <stdlib.h>

#include "http/header.h"
#include "http/message.h"
#include "http/request/parser.h"

void
httpRequestParserGetBody(HttpRequestParser this)
{
	HttpMessage message = (HttpMessage)(this->cur_request);
	char *      nbody;

	if (0 == message->nbody) {
		nbody = httpHeaderGet(
				&(message->header),
				"Content-Length");

		if (NULL == nbody) {
			this->state = HTTP_REQUEST_DONE;
			return;
		}
		else {
			message->type  = HTTP_MESSAGE_BUFFERED;
			message->nbody = atoi(nbody);
		}
	}

	if (REMAINS(this) >= message->nbody) {
		(message->body).buffer = calloc(1, message->nbody + 1);
		memcpy((message->body).buffer,
				this->cur_data,
				message->nbody);
		this->cur_data += message->nbody;
		this->state = HTTP_REQUEST_DONE;
	}
}

// vim: set ts=4 sw=4: