2 // Copyright (c) 2016-2019 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/_experimental/unit_test/suite.hpp>
24 class fields_test
: public beast::unit_test::suite
27 static constexpr std::size_t max_static_buffer
=
28 sizeof(beast::detail::temporary_buffer
);
36 test_allocator() noexcept(false) {}
38 template<class U
, class = typename
39 std::enable_if
<!std::is_same
<test_allocator
, U
>::value
>::type
>
40 test_allocator(test_allocator
<U
> const&) noexcept
{}
43 allocate(std::size_t n
)
45 return static_cast<value_type
*>(::operator new (n
*sizeof(value_type
)));
49 deallocate(value_type
* p
, std::size_t) noexcept
57 operator==(test_allocator
<T
> const&, test_allocator
<U
> const&) noexcept
65 operator!=(test_allocator
<T
> const& x
, test_allocator
<U
> const& y
) noexcept
71 using test_fields
= basic_fields
<test_allocator
<char>>;
73 BOOST_STATIC_ASSERT(is_fields
<fields
>::value
);
74 BOOST_STATIC_ASSERT(is_fields
<test_fields
>::value
);
76 // std::allocator is noexcept movable, fields should satisfy
77 // these constraints as well.
78 BOOST_STATIC_ASSERT(std::is_nothrow_move_constructible
<fields
>::value
);
79 BOOST_STATIC_ASSERT(std::is_nothrow_move_assignable
<fields
>::value
);
81 // Check if basic_fields respects throw-constructibility and
82 // propagate_on_container_move_assignment of the allocator.
83 BOOST_STATIC_ASSERT(std::is_nothrow_move_constructible
<test_fields
>::value
);
84 BOOST_STATIC_ASSERT(!std::is_nothrow_move_assignable
<test_fields
>::value
);
86 template<class Allocator
>
87 using fa_t
= basic_fields
<Allocator
>;
89 using f_t
= fa_t
<std::allocator
<char>>;
91 template<class Allocator
>
94 fill(std::size_t n
, basic_fields
<Allocator
>& f
)
96 for(std::size_t i
= 1; i
<= n
; ++i
)
97 f
.insert(std::to_string(i
), i
);
100 template<class U
, class V
>
103 self_assign(U
& u
, V
&& v
)
105 u
= std::forward
<V
>(v
);
108 template<class Alloc
>
111 empty(basic_fields
<Alloc
> const& f
)
113 return f
.begin() == f
.end();
116 template<class Alloc
>
119 size(basic_fields
<Alloc
> const& f
)
121 return std::distance(f
.begin(), f
.end());
127 using namespace test
;
130 using equal_t
= test::test_allocator
<char,
131 true, true, true, true, true>;
134 using unequal_t
= test::test_allocator
<char,
135 false, true, true, true, true>;
141 BEAST_EXPECT(f
.begin() == f
.end());
145 basic_fields
<unequal_t
> f
{a1
};
146 BEAST_EXPECT(f
.get_allocator() == a1
);
147 BEAST_EXPECT(f
.get_allocator() != unequal_t
{});
154 basic_fields
<equal_t
> f1
;
155 BEAST_EXPECT(f1
.get_allocator()->nmove
== 0);
157 BEAST_EXPECT(f1
["1"] == "1");
158 basic_fields
<equal_t
> f2
{std::move(f1
)};
159 BEAST_EXPECT(f2
.get_allocator()->nmove
== 1);
160 BEAST_EXPECT(f2
["1"] == "1");
161 BEAST_EXPECT(f1
["1"] == "");
165 basic_fields
<equal_t
> f1
;
168 basic_fields
<equal_t
> f2
{std::move(f1
), a
};
169 BEAST_EXPECT(f2
["1"] == "1");
170 BEAST_EXPECT(f1
["1"] == "");
173 // allocators unequal
174 basic_fields
<unequal_t
> f1
;
177 basic_fields
<unequal_t
> f2
{std::move(f1
), a
};
178 BEAST_EXPECT(f2
["1"] == "1");
185 basic_fields
<equal_t
> f1
;
187 basic_fields
<equal_t
> f2
{f1
};
188 BEAST_EXPECT(f1
.get_allocator() == f2
.get_allocator());
189 BEAST_EXPECT(f1
["1"] == "1");
190 BEAST_EXPECT(f2
["1"] == "1");
193 basic_fields
<unequal_t
> f1
;
196 basic_fields
<unequal_t
> f2(f1
, a
);
197 BEAST_EXPECT(f1
.get_allocator() != f2
.get_allocator());
198 BEAST_EXPECT(f1
["1"] == "1");
199 BEAST_EXPECT(f2
["1"] == "1");
202 basic_fields
<equal_t
> f1
;
204 basic_fields
<unequal_t
> f2(f1
);
205 BEAST_EXPECT(f1
["1"] == "1");
206 BEAST_EXPECT(f2
["1"] == "1");
209 basic_fields
<unequal_t
> f1
;
212 basic_fields
<equal_t
> f2(f1
, a
);
213 BEAST_EXPECT(f2
.get_allocator() == a
);
214 BEAST_EXPECT(f1
["1"] == "1");
215 BEAST_EXPECT(f2
["1"] == "1");
226 BEAST_EXPECT(f1
.begin() == f1
.end());
227 BEAST_EXPECT(f2
["1"] == "1");
230 // propagate_on_container_move_assignment : true
231 using pocma_t
= test::test_allocator
<char,
232 true, true, true, true, true>;
233 basic_fields
<pocma_t
> f1
;
235 basic_fields
<pocma_t
> f2
;
237 BEAST_EXPECT(f1
.begin() == f1
.end());
238 BEAST_EXPECT(f2
["1"] == "1");
241 // propagate_on_container_move_assignment : false
242 using pocma_t
= test::test_allocator
<char,
243 true, true, false, true, true>;
244 basic_fields
<pocma_t
> f1
;
246 basic_fields
<pocma_t
> f2
;
248 BEAST_EXPECT(f1
.begin() == f1
.end());
249 BEAST_EXPECT(f2
["1"] == "1");
260 BEAST_EXPECT(f1
["1"] == "1");
261 BEAST_EXPECT(f2
["1"] == "1");
262 basic_fields
<equal_t
> f3
;
264 BEAST_EXPECT(f3
["1"] == "1");
267 // propagate_on_container_copy_assignment : true
268 using pocca_t
= test::test_allocator
<char,
269 true, true, true, true, true>;
270 basic_fields
<pocca_t
> f1
;
272 basic_fields
<pocca_t
> f2
;
274 BEAST_EXPECT(f2
["1"] == "1");
277 // propagate_on_container_copy_assignment : false
278 using pocca_t
= test::test_allocator
<char,
279 true, false, true, true, true>;
280 basic_fields
<pocca_t
> f1
;
282 basic_fields
<pocca_t
> f2
;
284 BEAST_EXPECT(f2
["1"] == "1");
291 // propagate_on_container_swap : true
292 using pocs_t
= test::test_allocator
<char,
293 false, true, true, true, true>;
295 BEAST_EXPECT(a1
!= a2
);
296 basic_fields
<pocs_t
> f1
{a1
};
298 basic_fields
<pocs_t
> f2
{a2
};
299 BEAST_EXPECT(f1
.get_allocator() == a1
);
300 BEAST_EXPECT(f2
.get_allocator() == a2
);
302 BEAST_EXPECT(f1
.get_allocator() == a2
);
303 BEAST_EXPECT(f2
.get_allocator() == a1
);
304 BEAST_EXPECT(f1
.begin() == f1
.end());
305 BEAST_EXPECT(f2
["1"] == "1");
307 BEAST_EXPECT(f1
.get_allocator() == a1
);
308 BEAST_EXPECT(f2
.get_allocator() == a2
);
309 BEAST_EXPECT(f1
["1"] == "1");
310 BEAST_EXPECT(f2
.begin() == f2
.end());
313 // propagate_on_container_swap : false
314 using pocs_t
= test::test_allocator
<char,
315 true, true, true, false, true>;
317 BEAST_EXPECT(a1
== a2
);
318 BEAST_EXPECT(a1
.id() != a2
.id());
319 basic_fields
<pocs_t
> f1
{a1
};
321 basic_fields
<pocs_t
> f2
{a2
};
322 BEAST_EXPECT(f1
.get_allocator() == a1
);
323 BEAST_EXPECT(f2
.get_allocator() == a2
);
325 BEAST_EXPECT(f1
.get_allocator().id() == a1
.id());
326 BEAST_EXPECT(f2
.get_allocator().id() == a2
.id());
327 BEAST_EXPECT(f1
.begin() == f1
.end());
328 BEAST_EXPECT(f2
["1"] == "1");
330 BEAST_EXPECT(f1
.get_allocator().id() == a1
.id());
331 BEAST_EXPECT(f2
.get_allocator().id() == a2
.id());
332 BEAST_EXPECT(f1
["1"] == "1");
333 BEAST_EXPECT(f2
.begin() == f2
.end());
340 f
.insert(field::user_agent
, "x");
341 BEAST_EXPECT(f
.count(field::user_agent
));
342 BEAST_EXPECT(f
.count(to_string(field::user_agent
)));
343 BEAST_EXPECT(f
.count(field::user_agent
) == 1);
344 BEAST_EXPECT(f
.count(to_string(field::user_agent
)) == 1);
345 f
.insert(field::user_agent
, "y");
346 BEAST_EXPECT(f
.count(field::user_agent
) == 2);
353 BEAST_EXPECT(empty(f1
));
355 BEAST_EXPECT(size(f1
) == 1);
358 BEAST_EXPECT(size(f2
) == 1);
360 BEAST_EXPECT(std::distance(f2
.begin(), f2
.end()) == 2);
362 BEAST_EXPECT(size(f1
) == 2);
363 BEAST_EXPECT(size(f2
) == 0);
364 f_t
f3(std::move(f1
));
365 BEAST_EXPECT(size(f3
) == 2);
366 BEAST_EXPECT(size(f1
) == 0);
367 self_assign(f3
, std::move(f3
));
368 BEAST_EXPECT(size(f3
) == 2);
369 BEAST_EXPECT(f2
.erase("Not-Present") == 0);
379 BEAST_EXPECT(f
.count("a") == 2);
389 BEAST_EXPECT(size(f
) == 4);
391 BEAST_EXPECT(size(f
) == 2);
394 void testIteratorErase()
400 BEAST_EXPECT(size(f
) == 3);
401 f_t::const_iterator i
= std::next(f
.begin());
403 BEAST_EXPECT(size(f
) == 2);
404 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "a");
405 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "c");
414 f
.insert(field::age
, 1);
415 f
.insert(field::body
, 2);
416 f
.insert(field::close
, 3);
417 f
.insert(field::body
, 4);
418 BEAST_EXPECT(std::next(f
.begin(), 0)->name() == field::age
);
419 BEAST_EXPECT(std::next(f
.begin(), 1)->name() == field::body
);
420 BEAST_EXPECT(std::next(f
.begin(), 2)->name() == field::body
);
421 BEAST_EXPECT(std::next(f
.begin(), 3)->name() == field::close
);
422 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "Age");
423 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "Body");
424 BEAST_EXPECT(std::next(f
.begin(), 2)->name_string() == "Body");
425 BEAST_EXPECT(std::next(f
.begin(), 3)->name_string() == "Close");
426 BEAST_EXPECT(std::next(f
.begin(), 0)->value() == "1");
427 BEAST_EXPECT(std::next(f
.begin(), 1)->value() == "2");
428 BEAST_EXPECT(std::next(f
.begin(), 2)->value() == "4");
429 BEAST_EXPECT(std::next(f
.begin(), 3)->value() == "3");
430 BEAST_EXPECT(f
.erase(field::body
) == 2);
431 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "Age");
432 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "Close");
435 // group fields, case insensitive
441 BEAST_EXPECT(std::next(f
.begin(), 0)->name() == field::unknown
);
442 BEAST_EXPECT(std::next(f
.begin(), 1)->name() == field::unknown
);
443 BEAST_EXPECT(std::next(f
.begin(), 2)->name() == field::unknown
);
444 BEAST_EXPECT(std::next(f
.begin(), 3)->name() == field::unknown
);
445 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "a");
446 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "ab");
447 BEAST_EXPECT(std::next(f
.begin(), 2)->name_string() == "AB");
448 BEAST_EXPECT(std::next(f
.begin(), 3)->name_string() == "b");
449 BEAST_EXPECT(std::next(f
.begin(), 0)->value() == "1");
450 BEAST_EXPECT(std::next(f
.begin(), 1)->value() == "2");
451 BEAST_EXPECT(std::next(f
.begin(), 2)->value() == "4");
452 BEAST_EXPECT(std::next(f
.begin(), 3)->value() == "3");
453 BEAST_EXPECT(f
.erase("Ab") == 2);
454 BEAST_EXPECT(std::next(f
.begin(), 0)->name_string() == "a");
455 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "b");
458 // verify insertion orde
468 BEAST_EXPECT(f
.count("dd") == 4);
469 BEAST_EXPECT(std::next(f
.begin(), 1)->name_string() == "dd");
470 BEAST_EXPECT(std::next(f
.begin(), 2)->name_string() == "dD");
471 BEAST_EXPECT(std::next(f
.begin(), 3)->name_string() == "Dd");
472 BEAST_EXPECT(std::next(f
.begin(), 4)->name_string() == "DD");
474 BEAST_EXPECT(f
.count("dd") == 1);
475 BEAST_EXPECT(f
["dd"] == "-");
488 auto const rng
= f
.equal_range("B");
489 BEAST_EXPECT(std::distance(rng
.first
, rng
.second
) == 3);
490 BEAST_EXPECT(std::next(rng
.first
, 0)->value() == "2");
491 BEAST_EXPECT(std::next(rng
.first
, 1)->value() == "4");
492 BEAST_EXPECT(std::next(rng
.first
, 2)->value() == "6");
498 using value_type
= std::uint64_t;
502 size(value_type
const& v
)
510 struct value_type
{};
518 request
<empty_body
> req
;
520 req
.method(verb::get
);
522 req
.prepare_payload();
523 BEAST_EXPECT(req
.count(field::content_length
) == 0);
524 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
526 req
.set(field::content_length
, "0");
527 req
.set(field::transfer_encoding
, "chunked");
528 req
.prepare_payload();
530 BEAST_EXPECT(req
.count(field::content_length
) == 0);
531 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
533 req
.set(field::transfer_encoding
, "deflate");
534 req
.prepare_payload();
535 BEAST_EXPECT(req
.count(field::content_length
) == 0);
536 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
538 req
.set(field::transfer_encoding
, "deflate, chunked");
539 req
.prepare_payload();
540 BEAST_EXPECT(req
.count(field::content_length
) == 0);
541 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
546 request
<sized_body
> req
;
548 req
.method(verb::get
);
551 req
.prepare_payload();
552 BEAST_EXPECT(req
[field::content_length
] == "50");
553 BEAST_EXPECT(req
[field::transfer_encoding
] == "");
555 req
.set(field::content_length
, "0");
556 req
.set(field::transfer_encoding
, "chunked");
557 req
.prepare_payload();
558 BEAST_EXPECT(req
[field::content_length
] == "50");
559 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
561 req
.set(field::transfer_encoding
, "deflate, chunked");
562 req
.prepare_payload();
563 BEAST_EXPECT(req
[field::content_length
] == "50");
564 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
569 request
<empty_body
> req
;
571 req
.method(verb::put
);
573 req
.prepare_payload();
574 BEAST_EXPECT(req
[field::content_length
] == "0");
575 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
577 req
.set(field::content_length
, "50");
578 req
.set(field::transfer_encoding
, "deflate, chunked");
579 req
.prepare_payload();
580 BEAST_EXPECT(req
[field::content_length
] == "0");
581 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
586 request
<sized_body
> req
;
588 req
.method(verb::put
);
591 req
.prepare_payload();
592 BEAST_EXPECT(req
[field::content_length
] == "50");
593 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
595 req
.set(field::content_length
, "25");
596 req
.set(field::transfer_encoding
, "deflate, chunked");
597 req
.prepare_payload();
598 BEAST_EXPECT(req
[field::content_length
] == "50");
599 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
604 request
<unsized_body
> req
;
606 req
.method(verb::post
);
608 req
.prepare_payload();
609 BEAST_EXPECT(req
.count(field::content_length
) == 0);
610 BEAST_EXPECT(req
[field::transfer_encoding
] == "chunked");
612 req
.set(field::transfer_encoding
, "deflate");
613 req
.prepare_payload();
614 BEAST_EXPECT(req
.count(field::content_length
) == 0);
615 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate, chunked");
618 // POST, unsized HTTP/1.0
620 request
<unsized_body
> req
;
622 req
.method(verb::post
);
624 req
.prepare_payload();
625 BEAST_EXPECT(req
.count(field::content_length
) == 0);
626 BEAST_EXPECT(req
.count(field::transfer_encoding
) == 0);
628 req
.set(field::transfer_encoding
, "deflate");
629 req
.prepare_payload();
630 BEAST_EXPECT(req
.count(field::content_length
) == 0);
631 BEAST_EXPECT(req
[field::transfer_encoding
] == "deflate");
636 response
<empty_body
> res
;
639 res
.prepare_payload();
640 BEAST_EXPECT(res
[field::content_length
] == "0");
641 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
643 res
.erase(field::content_length
);
644 res
.set(field::transfer_encoding
, "chunked");
645 res
.prepare_payload();
646 BEAST_EXPECT(res
[field::content_length
] == "0");
647 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
652 response
<sized_body
> res
;
656 res
.prepare_payload();
657 BEAST_EXPECT(res
[field::content_length
] == "50");
658 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
660 res
.erase(field::content_length
);
661 res
.set(field::transfer_encoding
, "chunked");
662 res
.prepare_payload();
663 BEAST_EXPECT(res
[field::content_length
] == "50");
664 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
669 response
<unsized_body
> res
;
672 res
.prepare_payload();
673 BEAST_EXPECT(res
.count(field::content_length
) == 0);
674 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked");
681 response
<empty_body
> res
;
682 auto const keep_alive
=
687 (res
.keep_alive() && v
) ||
688 (! res
.keep_alive() && ! v
));
691 std::string
const big(max_static_buffer
+ 1, 'a');
695 res
.erase(field::connection
);
698 BEAST_EXPECT(res
.count(field::connection
) == 0);
700 res
.set(field::connection
, "close");
702 BEAST_EXPECT(res
.count(field::connection
) == 0);
704 res
.set(field::connection
, "keep-alive");
706 BEAST_EXPECT(res
.count(field::connection
) == 0);
708 res
.set(field::connection
, "keep-alive, close");
710 BEAST_EXPECT(res
.count(field::connection
) == 0);
712 res
.erase(field::connection
);
714 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
716 res
.set(field::connection
, "close");
718 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
720 res
.set(field::connection
, "keep-alive");
722 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
724 res
.set(field::connection
, "keep-alive, close");
726 BEAST_EXPECT(res
[field::connection
] == "keep-alive");
731 res
.set(field::connection
, s
);
733 BEAST_EXPECT(res
[field::connection
] == s
);
735 res
.set(field::connection
, s
+ ", close");
737 BEAST_EXPECT(res
[field::connection
] == s
);
739 res
.set(field::connection
, "keep-alive, " + s
);
741 BEAST_EXPECT(res
[field::connection
] == s
);
743 res
.set(field::connection
, "keep-alive, " + s
+ ", close");
745 BEAST_EXPECT(res
[field::connection
] == s
);
747 res
.set(field::connection
, s
);
749 BEAST_EXPECT(res
[field::connection
] == s
+ ", keep-alive");
751 res
.set(field::connection
, s
+ ", close");
753 BEAST_EXPECT(res
[field::connection
] == s
+ ", keep-alive");
755 res
.set(field::connection
, "keep-alive, " + s
);
757 BEAST_EXPECT(res
[field::connection
] == "keep-alive, " + s
);
759 res
.set(field::connection
, "keep-alive, " + s
+ ", close");
761 BEAST_EXPECT(res
[field::connection
] == "keep-alive, " + s
);
770 res
.erase(field::connection
);
772 BEAST_EXPECT(res
.count(field::connection
) == 0);
774 res
.set(field::connection
, "close");
776 BEAST_EXPECT(res
.count(field::connection
) == 0);
778 res
.set(field::connection
, "keep-alive");
780 BEAST_EXPECT(res
.count(field::connection
) == 0);
782 res
.set(field::connection
, "keep-alive, close");
784 BEAST_EXPECT(res
.count(field::connection
) == 0);
786 res
.erase(field::connection
);
788 BEAST_EXPECT(res
[field::connection
] == "close");
790 res
.set(field::connection
, "close");
792 BEAST_EXPECT(res
[field::connection
] == "close");
794 res
.set(field::connection
, "keep-alive");
796 BEAST_EXPECT(res
[field::connection
] == "close");
798 res
.set(field::connection
, "keep-alive, close");
800 BEAST_EXPECT(res
[field::connection
] == "close");
805 res
.set(field::connection
, s
);
807 BEAST_EXPECT(res
[field::connection
] == s
);
809 res
.set(field::connection
, s
+ ", close");
811 BEAST_EXPECT(res
[field::connection
] == s
);
813 res
.set(field::connection
, "keep-alive, " + s
);
815 BEAST_EXPECT(res
[field::connection
] == s
);
817 res
.set(field::connection
, "keep-alive, " + s
+ ", close");
819 BEAST_EXPECT(res
[field::connection
] == s
);
821 res
.set(field::connection
, s
);
823 BEAST_EXPECT(res
[field::connection
] == s
+ ", close");
825 res
.set(field::connection
, "close, " + s
);
827 BEAST_EXPECT(res
[field::connection
] == "close, " + s
);
829 res
.set(field::connection
, "keep-alive, " + s
);
831 BEAST_EXPECT(res
[field::connection
] == s
+ ", close");
833 res
.set(field::connection
, "close, " + s
+ ", keep-alive");
835 BEAST_EXPECT(res
[field::connection
] == "close, " + s
);
845 response
<empty_body
> res
{status::ok
, 11};
846 BEAST_EXPECT(res
.count(field::content_length
) == 0);
847 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
849 res
.content_length(0);
850 BEAST_EXPECT(res
[field::content_length
] == "0");
852 res
.content_length(100);
853 BEAST_EXPECT(res
[field::content_length
] == "100");
855 res
.content_length(boost::none
);
856 BEAST_EXPECT(res
.count(field::content_length
) == 0);
858 res
.set(field::transfer_encoding
, "chunked");
859 res
.content_length(0);
860 BEAST_EXPECT(res
[field::content_length
] == "0");
861 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
863 res
.set(field::transfer_encoding
, "chunked");
864 res
.content_length(100);
865 BEAST_EXPECT(res
[field::content_length
] == "100");
866 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
868 res
.set(field::transfer_encoding
, "chunked");
869 res
.content_length(boost::none
);
870 BEAST_EXPECT(res
.count(field::content_length
) == 0);
871 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
873 auto const check
= [&](std::string s
)
875 res
.set(field::transfer_encoding
, s
);
876 res
.content_length(0);
877 BEAST_EXPECT(res
[field::content_length
] == "0");
878 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
880 res
.set(field::transfer_encoding
, s
);
881 res
.content_length(100);
882 BEAST_EXPECT(res
[field::content_length
] == "100");
883 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
885 res
.set(field::transfer_encoding
, s
);
886 res
.content_length(boost::none
);
887 BEAST_EXPECT(res
.count(field::content_length
) == 0);
888 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
890 res
.set(field::transfer_encoding
, s
+ ", chunked");
891 res
.content_length(0);
892 BEAST_EXPECT(res
[field::content_length
] == "0");
893 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
895 res
.set(field::transfer_encoding
, s
+ ", chunked");
896 res
.content_length(100);
897 BEAST_EXPECT(res
[field::content_length
] == "100");
898 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
900 res
.set(field::transfer_encoding
, s
+ ", chunked");
901 res
.content_length(boost::none
);
902 BEAST_EXPECT(res
.count(field::content_length
) == 0);
903 BEAST_EXPECT(res
[field::transfer_encoding
] == s
);
905 res
.set(field::transfer_encoding
, "chunked, " + s
);
906 res
.content_length(0);
907 BEAST_EXPECT(res
[field::content_length
] == "0");
908 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, " + s
);
910 res
.set(field::transfer_encoding
, "chunked, " + s
);
911 res
.content_length(100);
912 BEAST_EXPECT(res
[field::content_length
] == "100");
913 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, " + s
);
915 res
.set(field::transfer_encoding
, "chunked, " + s
);
916 res
.content_length(boost::none
);
917 BEAST_EXPECT(res
.count(field::content_length
) == 0);
918 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, " + s
);
923 std::string
const big(max_static_buffer
+ 1, 'a');
931 response
<empty_body
> res
{status::ok
, 11};
932 BEAST_EXPECT(res
.count(field::content_length
) == 0);
933 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
940 (res
.chunked() && v
) ||
941 (! res
.chunked() && ! v
));
942 BEAST_EXPECT(res
.count(
943 field::content_length
) == 0);
946 res
.erase(field::transfer_encoding
);
947 res
.set(field::content_length
, 32);
949 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked");
951 res
.set(field::transfer_encoding
, "chunked");
953 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked");
955 res
.erase(field::transfer_encoding
);
956 res
.set(field::content_length
, 32);
958 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
960 res
.set(field::transfer_encoding
, "chunked");
962 BEAST_EXPECT(res
.count(field::transfer_encoding
) == 0);
966 res
.set(field::transfer_encoding
, "foo");
968 BEAST_EXPECT(res
[field::transfer_encoding
] == "foo, chunked");
970 res
.set(field::transfer_encoding
, "chunked, foo");
972 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo, chunked");
974 res
.set(field::transfer_encoding
, "chunked, foo, chunked");
976 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo, chunked");
978 res
.set(field::transfer_encoding
, "foo, chunked");
980 BEAST_EXPECT(res
[field::transfer_encoding
] == "foo");
982 res
.set(field::transfer_encoding
, "chunked, foo");
984 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo");
986 res
.set(field::transfer_encoding
, "chunked, foo, chunked");
988 BEAST_EXPECT(res
[field::transfer_encoding
] == "chunked, foo");
1000 testPreparePayload();
1003 testContentLength();
1008 BEAST_DEFINE_TESTSUITE(beast
,http
,fields
);