summaryrefslogtreecommitdiffstats
path: root/src/lib-http/http-response.c
blob: e85a73029f0254c88fbe9b146196b7c88d39b02b (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "istream.h"

#include "http-response.h"

void
http_response_init(struct http_response *resp,
	unsigned int status, const char *reason)
{
	i_zero(resp);
	resp->version_major = 1;
	resp->version_minor = 1;
	resp->date = ioloop_time;
	resp->status = status;
	resp->reason = reason;
}

bool http_response_has_connection_option(const struct http_response *resp,
	const char *option)
{
	const char *opt;

	if (!array_is_created(&resp->connection_options))
		return FALSE;
	array_foreach_elem(&resp->connection_options, opt) {
		if (strcasecmp(opt, option) == 0)
			return TRUE;
	}
	return FALSE;
}

int http_response_get_payload_size(const struct http_response *resp,
    uoff_t *size_r)
{
	if (resp->payload == NULL) {
		*size_r = 0;
		return 1;
	}

	return i_stream_get_size(resp->payload, TRUE, size_r);
}