Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
extension_permessage_compress.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
#include <websocketpp/common/memory.hpp>
#include <websocketpp/http/request.hpp>
#include <websocketpp/extensions/permessage_deflate/enabled.hpp>
Include dependency graph for extension_permessage_compress.cpp:

Go to the source code of this file.

Classes

struct  config
 

Macros

#define BOOST_TEST_MODULE   extension_permessage_deflate
 

Typedefs

typedef websocketpp::extensions::permessage_deflate::enabled< configcompressor_type
 

Functions

 BOOST_AUTO_TEST_CASE (deflate_init)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   extension_permessage_deflate

Definition at line 28 of file extension_permessage_compress.cpp.

Typedef Documentation

◆ compressor_type

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( deflate_init )

Window size is primarily controlled by the writer. A stream can only be read by a window size equal to or greater than the one use to compress it initially. The default windows size is also the maximum window size. Thus:

Outbound window size can be limited unilaterally under the assumption that the opposite end will be using the default (maximum size which can read anything)

Inbound window size must be limited by asking the remote endpoint to do so and it agreeing.

Context takeover is also primarily controlled by the writer. If the compressor does not clear its context between messages then the reader can't either.

Outbound messages may clear context between messages unilaterally. Inbound messages must retain state unless the remote endpoint signals otherwise.

Negotiation options: Client must choose from the following options:

  • whether or not to request an inbound window limit
  • whether or not to signal that it will honor an outbound window limit
  • whether or not to request that the server disallow context takeover

Server must answer in the following ways

  • If client requested a window size limit, is the window size limit acceptable?
  • If client allows window limit requests, should we send one?
  • If client requested no context takeover, should we accept?

All Defaults Req: permessage-compress; method=deflate Ans: permessage-compress; method=deflate

Client wants to limit the size of inbound windows from server

permessage-compress; method="deflate; s2c_max_window_bits=8, deflate" Ans: permessage-compress; method="deflate; s2c_max_window_bits=8" OR Ans: permessage-compress; method=deflate

Server wants to limit the size of inbound windows from client

Client: permessage-compress; method="deflate; c2s_max_window_bits, deflate"

Server: permessage-compress; method="deflate; c2s_max_window_bits=8"

Client wants to

Definition at line 46 of file extension_permessage_compress.cpp.

46 {
47 /*compressor_type compressor;
48 websocketpp::http::parser::attribute_list attributes;
49 std::pair<lib::error_code,std::string> neg_ret;
50
51 neg_ret = compressor.negotiate(attributes);
52
53 BOOST_CHECK_EQUAL( neg_ret.first,
54 extensions::permessage_deflate::error::invalid_parameters );*/
55
120 /* processor::extensions::deflate_method d(true);
121 http::parser::attribute_list attributes;
122 lib::error_code ec;
123
124 attributes.push_back(http::parser::attribute("foo","bar"));
125 ec = d.init(attributes);
126 BOOST_CHECK(ec == processor::extensions::error::unknown_method_parameter);
127
128 attributes.clear();
129 attributes.push_back(http::parser::attribute("s2c_max_window_bits","bar"));
130 ec = d.init(attributes);
131 BOOST_CHECK(ec == processor::extensions::error::invalid_algorithm_settings);
132
133 attributes.clear();
134 attributes.push_back(http::parser::attribute("s2c_max_window_bits","7"));
135 ec = d.init(attributes);
136 BOOST_CHECK(ec == processor::extensions::error::invalid_algorithm_settings);
137
138 attributes.clear();
139 attributes.push_back(http::parser::attribute("s2c_max_window_bits","16"));
140 ec = d.init(attributes);
141 BOOST_CHECK(ec == processor::extensions::error::invalid_algorithm_settings);
142
143 attributes.clear();
144 attributes.push_back(http::parser::attribute("s2c_max_window_bits","9"));
145 ec = d.init(attributes);
146 BOOST_CHECK( !ec);
147
148 attributes.clear();
149 ec = d.init(attributes);
150 BOOST_CHECK( !ec);
151
152 processor::extensions::deflate_engine de;
153
154 unsigned char test_in[] = "HelloHelloHelloHello";
155 unsigned char test_out[30];
156
157 uLongf test_out_size = 30;
158
159 int ret;
160
161 ret = compress(test_out, &test_out_size, test_in, 20);
162
163 std::cout << ret << std::endl
164 << websocketpp::utility::to_hex(test_in,20) << std::endl
165 << websocketpp::utility::to_hex(test_out,test_out_size) << std::endl;
166
167 std::string input = "Hello";
168 std::string output;
169 ec = de.compress(input,output);
170
171 BOOST_CHECK( ec == processor::extensions::error::uninitialized );
172
173 //std::cout << ec.message() << websocketpp::utility::to_hex(output) << std::endl;
174
175 ec = de.init(15,15,Z_DEFAULT_COMPRESSION,8,Z_FIXED);
176 //ec = de.init();
177 BOOST_CHECK( !ec );
178
179 ec = de.compress(input,output);
180 std::cout << ec.message() << std::endl
181 << websocketpp::utility::to_hex(input) << std::endl
182 << websocketpp::utility::to_hex(output) << std::endl;
183
184 output.clear();
185
186 ec = de.compress(input,output);
187 std::cout << ec.message() << std::endl
188 << websocketpp::utility::to_hex(input) << std::endl
189 << websocketpp::utility::to_hex(output) << std::endl;
190
191 input = output;
192 output.clear();
193 ec = de.decompress(input,output);
194 std::cout << ec.message() << std::endl
195 << websocketpp::utility::to_hex(input) << std::endl
196 << websocketpp::utility::to_hex(output) << std::endl;
197 */
198}