get_body.c
762 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
#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 = calloc(1, message->nbody + 1);
memcpy(message->body,
this->cur_data,
message->nbody);
this->cur_data += message->nbody;
this->state = HTTP_REQUEST_DONE;
}
}
// vim: set ts=4 sw=4: