forked from boostorg/beast
Deprecate string_param (API Change):
API Changes: `string_param`, which was previously the argument type when setting field values has been replaced by `string_view`. Because of this, it is no longer possible to set message field values directly as integrals. Users are required to convert numeric arguments to a string type prior to calling `fields::set` et. al. Beast provides the non-allocating `to_static_string()` function for this purpose. To set Content-Length field manually, call `message::content_length`. fixes #1956
This commit is contained in:
+27
-26
@@ -10,6 +10,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/http/fields.hpp>
|
||||
|
||||
#include <boost/beast/core/static_string.hpp>
|
||||
#include <boost/beast/http/empty_body.hpp>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/type_traits.hpp>
|
||||
@@ -94,7 +95,7 @@ public:
|
||||
fill(std::size_t n, basic_fields<Allocator>& f)
|
||||
{
|
||||
for(std::size_t i = 1; i<= n; ++i)
|
||||
f.insert(std::to_string(i), i);
|
||||
f.insert(std::to_string(i), to_static_string(i));
|
||||
}
|
||||
|
||||
template<class U, class V>
|
||||
@@ -411,10 +412,10 @@ public:
|
||||
{
|
||||
// group fields
|
||||
fields f;
|
||||
f.insert(field::age, 1);
|
||||
f.insert(field::body, 2);
|
||||
f.insert(field::close, 3);
|
||||
f.insert(field::body, 4);
|
||||
f.insert(field::age, to_static_string(1));
|
||||
f.insert(field::body, to_static_string(2));
|
||||
f.insert(field::close, to_static_string(3));
|
||||
f.insert(field::body, to_static_string(4));
|
||||
BEAST_EXPECT(std::next(f.begin(), 0)->name() == field::age);
|
||||
BEAST_EXPECT(std::next(f.begin(), 1)->name() == field::body);
|
||||
BEAST_EXPECT(std::next(f.begin(), 2)->name() == field::body);
|
||||
@@ -434,10 +435,10 @@ public:
|
||||
{
|
||||
// group fields, case insensitive
|
||||
fields f;
|
||||
f.insert("a", 1);
|
||||
f.insert("ab", 2);
|
||||
f.insert("b", 3);
|
||||
f.insert("AB", 4);
|
||||
f.insert("a", to_static_string(1));
|
||||
f.insert("ab", to_static_string(2));
|
||||
f.insert("b", to_static_string(3));
|
||||
f.insert("AB", to_static_string(4));
|
||||
BEAST_EXPECT(std::next(f.begin(), 0)->name() == field::unknown);
|
||||
BEAST_EXPECT(std::next(f.begin(), 1)->name() == field::unknown);
|
||||
BEAST_EXPECT(std::next(f.begin(), 2)->name() == field::unknown);
|
||||
@@ -457,14 +458,14 @@ public:
|
||||
{
|
||||
// verify insertion orde
|
||||
fields f;
|
||||
f.insert( "a", 1);
|
||||
f.insert("dd", 2);
|
||||
f.insert("b", 3);
|
||||
f.insert("dD", 4);
|
||||
f.insert("c", 5);
|
||||
f.insert("Dd", 6);
|
||||
f.insert("DD", 7);
|
||||
f.insert( "e", 8);
|
||||
f.insert( "a", to_static_string(1));
|
||||
f.insert("dd", to_static_string(2));
|
||||
f.insert("b", to_static_string(3));
|
||||
f.insert("dD", to_static_string(4));
|
||||
f.insert("c", to_static_string(5));
|
||||
f.insert("Dd", to_static_string(6));
|
||||
f.insert("DD", to_static_string(7));
|
||||
f.insert( "e", to_static_string(8));
|
||||
BEAST_EXPECT(f.count("dd") == 4);
|
||||
BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "dd");
|
||||
BEAST_EXPECT(std::next(f.begin(), 2)->name_string() == "dD");
|
||||
@@ -478,13 +479,13 @@ public:
|
||||
// equal_range
|
||||
{
|
||||
fields f;
|
||||
f.insert("E", 1);
|
||||
f.insert("B", 2);
|
||||
f.insert("D", 3);
|
||||
f.insert("B", 4);
|
||||
f.insert("C", 5);
|
||||
f.insert("B", 6);
|
||||
f.insert("A", 7);
|
||||
f.insert("E", to_static_string(1));
|
||||
f.insert("B", to_static_string(2));
|
||||
f.insert("D", to_static_string(3));
|
||||
f.insert("B", to_static_string(4));
|
||||
f.insert("C", to_static_string(5));
|
||||
f.insert("B", to_static_string(6));
|
||||
f.insert("A", to_static_string(7));
|
||||
auto const rng = f.equal_range("B");
|
||||
BEAST_EXPECT(std::distance(rng.first, rng.second) == 3);
|
||||
BEAST_EXPECT(std::next(rng.first, 0)->value() == "2");
|
||||
@@ -944,7 +945,7 @@ public:
|
||||
};
|
||||
|
||||
res.erase(field::transfer_encoding);
|
||||
res.set(field::content_length, 32);
|
||||
res.set(field::content_length, to_static_string(32));
|
||||
chunked(true);
|
||||
BEAST_EXPECT(res[field::transfer_encoding] == "chunked");
|
||||
|
||||
@@ -953,7 +954,7 @@ public:
|
||||
BEAST_EXPECT(res[field::transfer_encoding] == "chunked");
|
||||
|
||||
res.erase(field::transfer_encoding);
|
||||
res.set(field::content_length, 32);
|
||||
res.set(field::content_length, to_static_string(32));
|
||||
chunked(false);
|
||||
BEAST_EXPECT(res.count(field::transfer_encoding) == 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user