]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/http/fields.cpp
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 // Test that header file is self-contained.
11 #include <boost/beast/http/fields.hpp>
13 #include <boost/beast/http/empty_body.hpp>
14 #include <boost/beast/http/message.hpp>
15 #include <boost/beast/http/type_traits.hpp>
16 #include <boost/beast/test/test_allocator.hpp>
17 #include <boost/beast/unit_test/suite.hpp>
24 BOOST_STATIC_ASSERT(is_fields
<fields
>::value
);
26 class fields_test
: public beast::unit_test::suite
29 template<class Allocator
>
30 using fa_t
= basic_fields
<Allocator
>;
32 using f_t
= fa_t
<std::allocator
<char>>;
34 template<class Allocator
>
37 fill(std::size_t n
, basic_fields
<Allocator
>& f
)
39 for(std::size_t i
= 1; i
<= n
; ++i
)
40 f
.insert(std::to_string(i
), i
);
43 template<class U
, class V
>
46 self_assign(U
& u
, V
&& v
)
48 u
= std::forward
<V
>(v
);
54 empty(basic_fields
<Alloc
> const& f
)
56 return f
.begin() == f
.end();
62 size(basic_fields
<Alloc
> const& f
)
64 return std::distance(f
.begin(), f
.end());
73 using equal_t
= test::test_allocator
<char,
74 true, true, true, true, true>;
77 using unequal_t
= test::test_allocator
<char,
78 false, true, true, true, true>;
84 BEAST_EXPECT(f
.begin() == f
.end());
88 basic_fields
<unequal_t
> f
{a1
};
89 BEAST_EXPECT(f
.get_allocator() == a1
);
90 BEAST_EXPECT(f
.get_allocator() != unequal_t
{});
97 basic_fields
<equal_t
> f1
;
98 BEAST_EXPECT(f1
.get_allocator()->nmove
== 0);
100 BEAST_EXPECT(f1
["1"] == "1");
101 basic_fields
<equal_t
> f2
{std::move(f1
)};
102 BEAST_EXPECT(f2
.get_allocator()->nmove
== 1);
103 BEAST_EXPECT(f2
["1"] == "1");
104 BEAST_EXPECT(f1
["1"] == "");
108 basic_fields
<equal_t
> f1
;
111 basic_fields
<equal_t
> f2
{std::move(f1
), a
};
112 BEAST_EXPECT(f2
["1"] == "1");
113 BEAST_EXPECT(f1
["1"] == "");
116 // allocators unequal
117 basic_fields
<unequal_t
> f1
;
120 basic_fields
<unequal_t
> f2
{std::move(f1
), a
};
121 BEAST_EXPECT(f2
["1"] == "1");
128 basic_fields
<equal_t
> f1
;
130 basic_fields
<equal_t
> f2
{f1
};
131 BEAST_EXPECT(f1
.get_allocator() == f2
.get_allocator());
132 BEAST_EXPECT(f1
["1"] == "1");
133 BEAST_EXPECT(f2
["1"] == "1");
136 basic_fields
<unequal_t
> f1
;
139 basic_fields
<unequal_t
> f2(f1
, a
);
140 BEAST_EXPECT(f1
.get_allocator() != f2
.get_allocator());
141 BEAST_EXPECT(f1
["1"] == "1");
142 BEAST_EXPECT(f2
["1"] == "1");
145 basic_fields
<equal_t
> f1
;
147 basic_fields
<unequal_t
> f2(f1
);
148 BEAST_EXPECT(f1
["1"] == "1");
149 BEAST_EXPECT(f2
["1"] == "1");
152 basic_fields
<unequal_t
> f1
;
155 basic_fields
<equal_t
> f2(f1
, a
);
156 BEAST_EXPECT(f2
.get_allocator() == a
);
157 BEAST_EXPECT(f1
["1"] == "1");
158 BEAST_EXPECT(f2
["1"] == "1");
169 BEAST_EXPECT(f1
.begin() == f1
.end());
170 BEAST_EXPECT(f2
["1"] == "1");
173 // propagate_on_container_move_assignment : true
174 using pocma_t
= test::test_allocator
<char,
175 true, true, true, true, true>;
176 basic_fields
<pocma_t
> f1
;
178 basic_fields
<pocma_t
> f2
;
180 BEAST_EXPECT(f1
.begin() == f1
.end());
181 BEAST_EXPECT(f2
["1"] == "1");
184 // propagate_on_container_move_assignment : false
185 using pocma_t
= test::test_allocator
<char,
186 true, true, false, true, true>;
187 basic_fields
<pocma_t
> f1
;
189 basic_fields
<pocma_t
> f2
;
191 BEAST_EXPECT(f1
.begin() == f1
.end());
192 BEAST_EXPECT(f2
["1"] == "1");
203 BEAST_EXPECT(f1
["1"] == "1");
204 BEAST_EXPECT(f2
["1"] == "1");
205 basic_fields
<equal_t
> f3
;
207 BEAST_EXPECT(f3
["1"] == "1");
210 // propagate_on_container_copy_assignment : true
211 using pocca_t
= test::test_allocator
<char,
212 true, true, true, true, true>;
213 basic_fields
<pocca_t
> f1
;
215 basic_fields
<pocca_t
> f2
;
217 BEAST_EXPECT(f2
["1"] == "1");
220 // propagate_on_container_copy_assignment : false
221 using pocca_t
= test::test_allocator
<char,
222 true, false, true, true, true>;
223 basic_fields
<pocca_t
> f1
;
225 basic_fields
<pocca_t
> f2
;
227 BEAST_EXPECT(f2
["1"] == "1");
234 // propagate_on_container_swap : true
235 using pocs_t
= test::test_allocator
<char,
236 false, true, true, true, true>;
238 BEAST_EXPECT(a1
!= a2
);
239 basic_fields
<pocs_t
> f1
{a1
};
241 basic_fields
<pocs_t
> f2
{a2
};
242 BEAST_EXPECT(f1
.get_allocator() == a1
);
243 BEAST_EXPECT(f2
.get_allocator() == a2
);
245 BEAST_EXPECT(f1
.get_allocator() == a2
);
246 BEAST_EXPECT(f2
.get_allocator() == a1
);
247 BEAST_EXPECT(f1
.begin() == f1
.end());
248 BEAST_EXPECT(f2
["1"] == "1");
250 BEAST_EXPECT(f1
.get_allocator() == a1
);
251 BEAST_EXPECT(f2
.get_allocator() == a2
);
252 BEAST_EXPECT(f1
["1"] == "1");
253 BEAST_EXPECT(f2
.begin() == f2
.end());
256 // propagate_on_container_swap : false
257 using pocs_t
= test::test_allocator
<char,
258 true, true, true, false, true>;
260 BEAST_EXPECT(a1
== a2
);
261 BEAST_EXPECT(a1
.id() != a2
.id());
262 basic_fields
<pocs_t
> f1
{a1
};
264 basic_fields
<pocs_t
> f2
{a2
};
265 BEAST_EXPECT(f1
.get_allocator() == a1
);
266 BEAST_EXPECT(f2
.get_allocator() == a2
);
268 BEAST_EXPECT(f1
.get_allocator().id() == a1
.id());
269 BEAST_EXPECT(f2
.get_allocator().id() == a2
.id());
270 BEAST_EXPECT(f1
.begin() == f1
.end());
271 BEAST_EXPECT(f2
["1"] == "1");
273 BEAST_EXPECT(f1
.get_allocator().id() == a1
.id());
274 BEAST_EXPECT(f2
.get_allocator().id() == a2
.id());
275 BEAST_EXPECT(f1
["1"] == "1");
276 BEAST_EXPECT(f2
.begin() == f2
.end());
283 f
.insert(field::user_agent
, "x");
284 BEAST_EXPECT(f
.count(field::user_agent
));
285 BEAST_EXPECT(f
.count(to_string(field::user_agent
)));
286 BEAST_EXPECT(f
.count(field::user_agent
) == 1);
287 BEAST_EXPECT(f
.count(to_string(field::user_agent
)) == 1);
288 f
.insert(field::user_agent
, "y");
289 BEAST_EXPECT(f
.count(field::user_agent
) == 2);
296 BEAST_EXPECT(empty(f1
));
298 BEAST_EXPECT(size(f1
) == 1);
301 BEAST_EXPECT(size(f2
) == 1);
303 BEAST_EXPECT(std::distance(f2
.begin(), f2
.end()) == 2);
305 BEAST_EXPECT(size(f1
) == 2);
306 BEAST_EXPECT(size(f2
) == 0);
307 f_t
f3(std::move(f1
));
308 BEAST_EXPECT(size(f3
) == 2);
309 BEAST_EXPECT(size(f1
) == 0);
310 self_assign(f3
, std::move(f3
));
311 BEAST_EXPECT(size(f3
) == 2);
312 BEAST_EXPECT(f2
.erase("Not-Present") == 0);
322 BEAST_EXPECT(f
.count("a") == 2);
332 BEAST_EXPECT(size(f
) == 4);
334 BEAST_EXPECT(size(f
) == 2);
343 f
.insert(field::age
, 1);
344 f
.insert(field::body
, 2);
345 f
.insert(field::close
, 3);
346 f
.insert(field::body
, 4);
347 BEAST_EXPECT(std::next(f
.begin(), 0)->name() == field::age
);
348 BEAST_EXPECT(std::next(f
.begin(), 1)->name() == field::body
);
349 BEAST_EXPECT(std::next(f
.begin(), 2)->name() == field::body
);
350 BEAST_EXPECT(std::next(f
.begin(), 3)->name() == field::close
);
351 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "Age");
352 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "Body");
353 BEAST_EXPECT(std::next(f
.begin(), 2)->name_string() == "Body");
354 BEAST_EXPECT(std::next(f
.begin(), 3)->name_string() == "Close");
355 BEAST_EXPECT(std::next(f
.begin(), 0)->value() == "1");
356 BEAST_EXPECT(std::next(f
.begin(), 1)->value() == "2");
357 BEAST_EXPECT(std::next(f
.begin(), 2)->value() == "4");
358 BEAST_EXPECT(std::next(f
.begin(), 3)->value() == "3");
359 BEAST_EXPECT(f
.erase(field::body
) == 2);
360 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "Age");
361 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "Close");
364 // group fields, case insensitive
370 BEAST_EXPECT(std::next(f
.begin(), 0)->name() == field::unknown
);
371 BEAST_EXPECT(std::next(f
.begin(), 1)->name() == field::unknown
);
372 BEAST_EXPECT(std::next(f
.begin(), 2)->name() == field::unknown
);
373 BEAST_EXPECT(std::next(f
.begin(), 3)->name() == field::unknown
);
374 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "a");
375 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "ab");
376 BEAST_EXPECT(std::next(f
.begin(), 2)->name_string() == "AB");
377 BEAST_EXPECT(std::next(f
.begin(), 3)->name_string() == "b");
378 BEAST_EXPECT(std::next(f
.begin(), 0)->value() == "1");
379 BEAST_EXPECT(std::next(f
.begin(), 1)->value() == "2");
380 BEAST_EXPECT(std::next(f
.begin(), 2)->value() == "4");
381 BEAST_EXPECT(std::next(f
.begin(), 3)->value() == "3");
382 BEAST_EXPECT(f
.erase("Ab") == 2);
383 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "a");
384 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "b");
387 // verify insertion orde
397 BEAST_EXPECT(f
.count("dd") == 4);
398 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "dd");
399 BEAST_EXPECT(std::next(f
.begin(), 2)->name_string() == "dD");
400 BEAST_EXPECT(std::next(f
.begin(), 3)->name_string() == "Dd");
401 BEAST_EXPECT(std::next(f
.begin(), 4)->name_string() == "DD");
403 BEAST_EXPECT(f
.count("dd") == 1);
404 BEAST_EXPECT(f
["dd"] == "-");
417 auto const rng
= f
.equal_range("B");
418 BEAST_EXPECT(std::distance(rng
.first
, rng
.second
) == 3);
419 BEAST_EXPECT(std::next(rng
.first
, 0)->value() == "2");
420 BEAST_EXPECT(std::next(rng
.first
, 1)->value() == "4");
421 BEAST_EXPECT(std::next(rng
.first
, 2)->value() == "6");
427 using value_type
= std::uint64_t;
431 size(value_type
const& v
)
439 struct value_type
{};
447 request
<empty_body
> req
;
449 req
.method(verb::get
);
451 req
.prepare_payload();
452 BEAST_EXPECT(req
.count(field::content_length
) == 0);
453 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
455 req
.set(field::content_length
, "0");
456 req
.set(field::transfer_encoding
, "chunked");
457 req
.prepare_payload();
459 BEAST_EXPECT(req
.count(field::content_length
) == 0);
460 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
462 req
.set(field::transfer_encoding
, "deflate");
463 req
.prepare_payload();
464 BEAST_EXPECT(req
.count(field::content_length
) == 0);
465 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
467 req
.set(field::transfer_encoding
, "deflate, chunked");
468 req
.prepare_payload();
469 BEAST_EXPECT(req
.count(field::content_length
) == 0);
470 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
475 request
<sized_body
> req
;
477 req
.method(verb::get
);
480 req
.prepare_payload();
481 BEAST_EXPECT(req
[field::content_length
] == "50");
482 BEAST_EXPECT(req
[field::transfer_encoding
] == "");
484 req
.set(field::content_length
, "0");
485 req
.set(field::transfer_encoding
, "chunked");
486 req
.prepare_payload();
487 BEAST_EXPECT(req
[field::content_length
] == "50");
488 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
490 req
.set(field::transfer_encoding
, "deflate, chunked");
491 req
.prepare_payload();
492 BEAST_EXPECT(req
[field::content_length
] == "50");
493 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
498 request
<empty_body
> req
;
500 req
.method(verb::put
);
502 req
.prepare_payload();
503 BEAST_EXPECT(req
[field::content_length
] == "0");
504 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
506 req
.set(field::content_length
, "50");
507 req
.set(field::transfer_encoding
, "deflate, chunked");
508 req
.prepare_payload();
509 BEAST_EXPECT(req
[field::content_length
] == "0");
510 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
515 request
<sized_body
> req
;
517 req
.method(verb::put
);
520 req
.prepare_payload();
521 BEAST_EXPECT(req
[field::content_length
] == "50");
522 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
524 req
.set(field::content_length
, "25");
525 req
.set(field::transfer_encoding
, "deflate, chunked");
526 req
.prepare_payload();
527 BEAST_EXPECT(req
[field::content_length
] == "50");
528 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
533 request
<unsized_body
> req
;
535 req
.method(verb::post
);
537 req
.prepare_payload();
538 BEAST_EXPECT(req
.count(field::content_length
) == 0);
539 BEAST_EXPECT(req
[field::transfer_encoding
] == "chunked");
541 req
.set(field::transfer_encoding
, "deflate");
542 req
.prepare_payload();
543 BEAST_EXPECT(req
.count(field::content_length
) == 0);
544 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate, chunked");
547 // POST, unsized HTTP/1.0
549 request
<unsized_body
> req
;
551 req
.method(verb::post
);
553 req
.prepare_payload();
554 BEAST_EXPECT(req
.count(field::content_length
) == 0);
555 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
557 req
.set(field::transfer_encoding
, "deflate");
558 req
.prepare_payload();
559 BEAST_EXPECT(req
.count(field::content_length
) == 0);
560 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
565 response
<empty_body
> res
;
568 res
.prepare_payload();
569 BEAST_EXPECT(res
[field::content_length
] == "0");
570 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
572 res
.erase(field::content_length
);
573 res
.set(field::transfer_encoding
, "chunked");
574 res
.prepare_payload();
575 BEAST_EXPECT(res
[field::content_length
] == "0");
576 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
581 response
<sized_body
> res
;
585 res
.prepare_payload();
586 BEAST_EXPECT(res
[field::content_length
] == "50");
587 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
589 res
.erase(field::content_length
);
590 res
.set(field::transfer_encoding
, "chunked");
591 res
.prepare_payload();
592 BEAST_EXPECT(res
[field::content_length
] == "50");
593 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
598 response
<unsized_body
> res
;
601 res
.prepare_payload();
602 BEAST_EXPECT(res
.count(field::content_length
) == 0);
603 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked");
610 response
<empty_body
> res
;
611 auto const keep_alive
=
616 (res
.keep_alive() && v
) ||
617 (! res
.keep_alive() && ! v
));
620 BOOST_STATIC_ASSERT(fields::max_static_buffer
== 4096);
621 std::string
const big(4096 + 1, 'a');
625 res
.erase(field::connection
);
628 BEAST_EXPECT(res
.count(field::connection
) == 0);
630 res
.set(field::connection
, "close");
632 BEAST_EXPECT(res
.count(field::connection
) == 0);
634 res
.set(field::connection
, "keep-alive");
636 BEAST_EXPECT(res
.count(field::connection
) == 0);
638 res
.set(field::connection
, "keep-alive, close");
640 BEAST_EXPECT(res
.count(field::connection
) == 0);
642 res
.erase(field::connection
);
644 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
646 res
.set(field::connection
, "close");
648 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
650 res
.set(field::connection
, "keep-alive");
652 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
654 res
.set(field::connection
, "keep-alive, close");
656 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
661 res
.set(field::connection
, s
);
663 BEAST_EXPECT(res
[field::connection
] == s
);
665 res
.set(field::connection
, s
+ ", close");
667 BEAST_EXPECT(res
[field::connection
] == s
);
669 res
.set(field::connection
, "keep-alive, " + s
);
671 BEAST_EXPECT(res
[field::connection
] == s
);
673 res
.set(field::connection
, "keep-alive, " + s
+ ", close");
675 BEAST_EXPECT(res
[field::connection
] == s
);
677 res
.set(field::connection
, s
);
679 BEAST_EXPECT(res
[field::connection
] == s
+ ", keep-alive");
681 res
.set(field::connection
, s
+ ", close");
683 BEAST_EXPECT(res
[field::connection
] == s
+ ", keep-alive");
685 res
.set(field::connection
, "keep-alive, " + s
);
687 BEAST_EXPECT(res
[field::connection
] == "keep-alive, " + s
);
689 res
.set(field::connection
, "keep-alive, " + s
+ ", close");
691 BEAST_EXPECT(res
[field::connection
] == "keep-alive, " + s
);
700 res
.erase(field::connection
);
702 BEAST_EXPECT(res
.count(field::connection
) == 0);
704 res
.set(field::connection
, "close");
706 BEAST_EXPECT(res
.count(field::connection
) == 0);
708 res
.set(field::connection
, "keep-alive");
710 BEAST_EXPECT(res
.count(field::connection
) == 0);
712 res
.set(field::connection
, "keep-alive, close");
714 BEAST_EXPECT(res
.count(field::connection
) == 0);
716 res
.erase(field::connection
);
718 BEAST_EXPECT(res
[field::connection
] == "close");
720 res
.set(field::connection
, "close");
722 BEAST_EXPECT(res
[field::connection
] == "close");
724 res
.set(field::connection
, "keep-alive");
726 BEAST_EXPECT(res
[field::connection
] == "close");
728 res
.set(field::connection
, "keep-alive, close");
730 BEAST_EXPECT(res
[field::connection
] == "close");
735 res
.set(field::connection
, s
);
737 BEAST_EXPECT(res
[field::connection
] == s
);
739 res
.set(field::connection
, s
+ ", close");
741 BEAST_EXPECT(res
[field::connection
] == s
);
743 res
.set(field::connection
, "keep-alive, " + s
);
745 BEAST_EXPECT(res
[field::connection
] == s
);
747 res
.set(field::connection
, "keep-alive, " + s
+ ", close");
749 BEAST_EXPECT(res
[field::connection
] == s
);
751 res
.set(field::connection
, s
);
753 BEAST_EXPECT(res
[field::connection
] == s
+ ", close");
755 res
.set(field::connection
, "close, " + s
);
757 BEAST_EXPECT(res
[field::connection
] == "close, " + s
);
759 res
.set(field::connection
, "keep-alive, " + s
);
761 BEAST_EXPECT(res
[field::connection
] == s
+ ", close");
763 res
.set(field::connection
, "close, " + s
+ ", keep-alive");
765 BEAST_EXPECT(res
[field::connection
] == "close, " + s
);
775 response
<empty_body
> res
{status::ok
, 11};
776 BEAST_EXPECT(res
.count(field::content_length
) == 0);
777 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
779 res
.content_length(0);
780 BEAST_EXPECT(res
[field::content_length
] == "0");
782 res
.content_length(100);
783 BEAST_EXPECT(res
[field::content_length
] == "100");
785 res
.content_length(boost::none
);
786 BEAST_EXPECT(res
.count(field::content_length
) == 0);
788 res
.set(field::transfer_encoding
, "chunked");
789 res
.content_length(0);
790 BEAST_EXPECT(res
[field::content_length
] == "0");
791 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
793 res
.set(field::transfer_encoding
, "chunked");
794 res
.content_length(100);
795 BEAST_EXPECT(res
[field::content_length
] == "100");
796 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
798 res
.set(field::transfer_encoding
, "chunked");
799 res
.content_length(boost::none
);
800 BEAST_EXPECT(res
.count(field::content_length
) == 0);
801 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
803 auto const check
= [&](std::string s
)
805 res
.set(field::transfer_encoding
, s
);
806 res
.content_length(0);
807 BEAST_EXPECT(res
[field::content_length
] == "0");
808 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
810 res
.set(field::transfer_encoding
, s
);
811 res
.content_length(100);
812 BEAST_EXPECT(res
[field::content_length
] == "100");
813 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
815 res
.set(field::transfer_encoding
, s
);
816 res
.content_length(boost::none
);
817 BEAST_EXPECT(res
.count(field::content_length
) == 0);
818 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
820 res
.set(field::transfer_encoding
, s
+ ", chunked");
821 res
.content_length(0);
822 BEAST_EXPECT(res
[field::content_length
] == "0");
823 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
825 res
.set(field::transfer_encoding
, s
+ ", chunked");
826 res
.content_length(100);
827 BEAST_EXPECT(res
[field::content_length
] == "100");
828 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
830 res
.set(field::transfer_encoding
, s
+ ", chunked");
831 res
.content_length(boost::none
);
832 BEAST_EXPECT(res
.count(field::content_length
) == 0);
833 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
835 res
.set(field::transfer_encoding
, "chunked, " + s
);
836 res
.content_length(0);
837 BEAST_EXPECT(res
[field::content_length
] == "0");
838 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, " + s
);
840 res
.set(field::transfer_encoding
, "chunked, " + s
);
841 res
.content_length(100);
842 BEAST_EXPECT(res
[field::content_length
] == "100");
843 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, " + s
);
845 res
.set(field::transfer_encoding
, "chunked, " + s
);
846 res
.content_length(boost::none
);
847 BEAST_EXPECT(res
.count(field::content_length
) == 0);
848 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, " + s
);
853 BOOST_STATIC_ASSERT(fields::max_static_buffer
== 4096);
854 std::string
const big(4096 + 1, 'a');
862 response
<empty_body
> res
{status::ok
, 11};
863 BEAST_EXPECT(res
.count(field::content_length
) == 0);
864 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
871 (res
.chunked() && v
) ||
872 (! res
.chunked() && ! v
));
873 BEAST_EXPECT(res
.count(
874 field::content_length
) == 0);
877 res
.erase(field::transfer_encoding
);
878 res
.set(field::content_length
, 32);
880 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked");
882 res
.set(field::transfer_encoding
, "chunked");
884 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked");
886 res
.erase(field::transfer_encoding
);
887 res
.set(field::content_length
, 32);
889 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
891 res
.set(field::transfer_encoding
, "chunked");
893 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
897 res
.set(field::transfer_encoding
, "foo");
899 BEAST_EXPECT(res
[field::transfer_encoding
] == "foo, chunked");
901 res
.set(field::transfer_encoding
, "chunked, foo");
903 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo, chunked");
905 res
.set(field::transfer_encoding
, "chunked, foo, chunked");
907 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo, chunked");
909 res
.set(field::transfer_encoding
, "foo, chunked");
911 BEAST_EXPECT(res
[field::transfer_encoding
] == "foo");
913 res
.set(field::transfer_encoding
, "chunked, foo");
915 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo");
917 res
.set(field::transfer_encoding
, "chunked, foo, chunked");
919 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo");
930 testPreparePayload();
938 BEAST_DEFINE_TESTSUITE(beast
,http
,fields
);