From c2cbb0c468f3161d84342e6f1051d0adfee8b1ca Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 24 Nov 2023 22:30:06 +0300 Subject: [PATCH] Explicitly pass content-type of the test HTTP query. --- test/http.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/http.cpp b/test/http.cpp index e3d2301f6..a8c796146 100644 --- a/test/http.cpp +++ b/test/http.cpp @@ -71,13 +71,13 @@ static td::string gen_http_content() { return td::rand_string(std::numeric_limits::min(), std::numeric_limits::max(), len); } -static td::string make_http_query(td::string content, bool is_json, bool is_chunked, bool is_gzip, double gzip_k = 5, - td::string zip_override = td::string()) { +static td::string make_http_query(td::string content, td::string content_type, bool is_chunked, bool is_gzip, + double gzip_k = 5, td::string zip_override = td::string()) { td::HttpHeaderCreator hc; hc.init_post("/"); hc.add_header("jfkdlsahhjk", td::rand_string('a', 'z', td::Random::fast(1, 2000))); - if (is_json) { - hc.add_header("content-type", "application/json"); + if (!content_type.empty()) { + hc.add_header("content-type", content_type); } if (is_gzip) { td::BufferSlice zip; @@ -105,7 +105,7 @@ static td::string make_http_query(td::string content, bool is_json, bool is_chun static td::string rand_http_query(td::string content) { bool is_chunked = td::Random::fast_bool(); bool is_gzip = td::Random::fast_bool(); - return make_http_query(std::move(content), false, is_chunked, is_gzip); + return make_http_query(std::move(content), td::string(), is_chunked, is_gzip); } static td::string join(const td::vector &v) { @@ -220,7 +220,7 @@ TEST(Http, gzip_bomb) { .as_slice() .str(); - auto query = make_http_query("", false, false, true, 0.01, gzip_bomb_str); + auto query = make_http_query(td::string(), td::string(), false, true, 0.01, gzip_bomb_str); auto parts = td::rand_split(query); td::ChainBufferWriter input_writer; auto input = input_writer.extract_reader(); @@ -248,7 +248,7 @@ TEST(Http, gzip) { td::HttpReader reader; reader.init(&input, 0, 0); - auto query = make_http_query("", true, false, true, 0.01, gzip_str); + auto query = make_http_query(td::string(), "application/json", false, true, 0.01, gzip_str); input_writer.append(query); input.sync_with_writer(); @@ -442,7 +442,7 @@ TEST(Http, gzip_bomb_with_limit) { gzip_bomb_str = sink.result()->move_as_buffer_slice().as_slice().str(); } - auto query = make_http_query("", false, false, true, 0.01, gzip_bomb_str); + auto query = make_http_query(td::string(), td::string(), false, true, 0.01, gzip_bomb_str); auto parts = td::rand_split(query); td::ChainBufferWriter input_writer; auto input = input_writer.extract_reader();