about summary refs log tree commit diff
path: root/src/response.c
blob: 1000da6e1772edc1bc23d9aef63f22394d41a425 (plain)
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
#include "libhttpc.h"

#include <stddef.h>
#include <string.h>


char *LibHTTPC_dumpResponse(struct LibHTTPC_Response *response, char *buf, size_t buf_len)
{
    if (!response->version || !response->status || !response->phrase)
        return NULL;

#define append(X) strncat(buf, (X), buf_len - strlen(buf))
    append(response->version);
    append("");
    append(response->status);
    append(" ");
    append(response->phrase);
    append("\r\n");
    for (size_t i = 0; i < response->header_count; ++i)
    {
        append(response->header_names[i]);
        append(": ");
        append(response->header_values[i]);
        append("\r\n");
    }
    append("\r\n");
    if (response->body)
        append(response->body);
#undef append

    return NULL;
}