http-server-response.c revision 903f0b38884375179cea63b9d0821e295c38764a
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2013-2016 Dovecot authors, see the included COPYING file */
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainenstatic inline void
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainenhttp_server_response_debug(struct http_server_response *resp,
43834f87bf431198f986e86052a4f6e558fdb07dTimo Sirainenstatic inline void
43834f87bf431198f986e86052a4f6e558fdb07dTimo Sirainenhttp_server_response_debug(struct http_server_response *resp,
09801f106cd531a28b4e03ec665e44c421264560Timo Sirainen const char *format, ...)
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen i_debug("http-server: request %s; %u response: %s",
212a34c06ff45952c008ae9eec387ced783de6cfPhil Carmody http_server_request_label(resp->request), resp->status,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenhttp_server_response_create(struct http_server_request *req,
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen /* was already composing a response, but decided to
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen start a new one (would usually be a failure response)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid http_server_response_free(struct http_server_response *resp)
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainenvoid http_server_response_add_header(struct http_server_response *resp,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen i_assert(strchr(key, '\r') == NULL && strchr(key, '\n') == NULL);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen i_assert(strchr(value, '\r') == NULL && strchr(value, '\n') == NULL);
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen /* mark presence of special headers */
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen switch (key[0]) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen else if (strcasecmp(key, "Content-Length") == 0)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (strcasecmp(key, "Transfer-Encoding") == 0)
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen str_printfa(resp->headers, "%s: %s\r\n", key, value);
01f4ee4a0243f3fe9af763e1a540cd5cff0d63f5Timo Sirainenvoid http_server_response_update_status(struct http_server_response *resp,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen unsigned int status,
7d207b1e77a7b5e3fda640e353acfc86d261fedfTimo Sirainen /* free not called because pool is alloconly */
01f4ee4a0243f3fe9af763e1a540cd5cff0d63f5Timo Sirainen resp->reason = p_strdup(resp->request->pool, reason);
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainenvoid http_server_response_set_date(struct http_server_response *resp,
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainenvoid http_server_response_set_payload(struct http_server_response *resp,
6f08b98ac63c25b747120d0c8f8e319b4e26ab0fTimo Sirainen if ((ret = i_stream_get_size(input, TRUE, &resp->payload_size)) <= 0) {
699fdc186f982f70d990820796eaa0f12133e27cTimo Sirainenvoid http_server_response_set_payload_data(struct http_server_response *resp,
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen unsigned char *payload_data;
282a436a74d8835edb45cc019b1c916013013fd3Timo Sirainen payload_data = p_malloc(resp->request->pool, size);
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen input = i_stream_create_from_data(payload_data, size);
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen http_server_response_set_payload(resp, input);
bool close)
unsigned int iov_count, i;
if (ret > 0) {
if (i < iov_count) {
int ret;
ret = 0;
return ret;
const char **error_r)
const char **error_r)
int ret = 0;
if (ret >= 0) {
return ret;
const char **error_r)
int ret;
T_BEGIN {
if (ret < 0)
} T_END;
return ret;
struct http_server_ostream {
static ssize_t
ret = 0;
for (i = 0; i < iov_count; i++)
return ret;
struct ostream *
bool blocking)