aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/http/io/stream_ut_medium.cpp
blob: 4ac4fffb9b942f8360f19b68e6802bdf47163385 (plain) (blame)
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
47
48
49
50
51
52
53
54
#include "stream.h"
#include <library/cpp/testing/unittest/registar.h> 
#include <util/stream/zlib.h>

Y_UNIT_TEST_SUITE(THttpTestMedium) {
    Y_UNIT_TEST(TestCodings2) {
        TStringBuf data = "aaaaaaaaaaaaaaaaaaaaaaa";

        for (auto codec : SupportedCodings()) {
            if (codec == TStringBuf("z-zlib-0")) {
                continue;
            }

            if (codec == TStringBuf("z-null")) {
                continue;
            }

            TString s;

            {
                TStringOutput so(s);
                THttpOutput ho(&so);
                TBufferedOutput bo(&ho, 10000);

                bo << "HTTP/1.1 200 Ok\r\n"
                   << "Connection: close\r\n"
                   << "Content-Encoding: " << codec << "\r\n\r\n";

                for (size_t i = 0; i < 100; ++i) {
                    bo << data;
                }
            }

            try {
                UNIT_ASSERT(s.size() > 10);
                UNIT_ASSERT(s.find(data) == TString::npos);
            } catch (...) {
                Cerr << codec << " " << s << Endl;

                throw;
            }

            {
                TStringInput si(s);
                THttpInput hi(&si);

                auto res = hi.ReadAll();

                UNIT_ASSERT(res.find(data) == 0);
            }
        }
    }

} // THttpTestMedium suite