bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
a81d5c3f5a4ad5d100b258d10d4c75f4a02ab1f6Stephan Bosch
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch#include "lib.h"
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch#include "array.h"
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch#include "istream.h"
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch#include "http-request.h"
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Boschbool http_request_has_connection_option(const struct http_request *req,
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch const char *option)
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch{
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch const char *const *opt_idx;
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch
8b223f08b8ab40fd4e6a65542aac9ab6afc6839dStephan Bosch if (!array_is_created(&req->connection_options))
8b223f08b8ab40fd4e6a65542aac9ab6afc6839dStephan Bosch return FALSE;
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch array_foreach(&req->connection_options, opt_idx) {
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch if (strcasecmp(*opt_idx, option) == 0)
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch return TRUE;
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch }
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch return FALSE;
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch}
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Boschint http_request_get_payload_size(const struct http_request *req,
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch uoff_t *size_r)
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch{
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch if (req->payload == NULL) {
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch *size_r = 0;
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch return 1;
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch }
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch return i_stream_get_size(req->payload, TRUE, size_r);
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch}