#include "lib.h"
#include "array.h"
#include "istream.h"
+#include "iostream.h"
+#include "istream-sized.h"
#include "http-parser.h"
#include "http-header.h"
#include "http-header-parser.h"
return ret;
}
+static const char *
+http_istream_error_callback(const struct istream_sized_error_data *data,
+ struct istream *input)
+{
+ i_assert(data->eof);
+ i_assert(data->v_offset + data->new_bytes < data->wanted_size);
+
+ return t_strdup_printf("Disconnected from server at offset %"PRIuUOFF_T
+ " (wanted %"PRIuUOFF_T"): %s", data->v_offset + data->new_bytes,
+ data->wanted_size, io_stream_get_disconnect_reason(input, NULL));
+}
+
int http_message_parse_body(struct http_message_parser *parser, bool request)
{
+ struct istream *input;
+
parser->error_code = HTTP_MESSAGE_PARSE_ERROR_NONE;
parser->error = NULL;
}
/* Got explicit message size from Content-Length: header */
- parser->payload =
- i_stream_create_limit(parser->input,
+ input = i_stream_create_limit(parser->input,
parser->msg.content_length);
+ /* Make sure we return failure if HTTP connection closes before
+ we've finished reading the full input. */
+ parser->payload = i_stream_create_sized_with_callback(input,
+ parser->msg.content_length,
+ http_istream_error_callback, input);
+ i_stream_unref(&input);
} else if (!parser->msg.have_content_length && !request) {
/* RFC 7230, Section 3.3.3: Message Body Length