|
| 1 | +// Copyright 2013 Rudolfs Bundulis |
| 2 | +// Distributed under the Boost Software License, Version 1.0. |
| 3 | +// (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 5 | + |
| 6 | +#define BOOST_TEST_MODULE HTTP Server Header Parser Test |
| 7 | +#include <boost/network/protocol/http/server.hpp> |
| 8 | +#include <boost/config/warning_disable.hpp> |
| 9 | +#include <boost/test/unit_test.hpp> |
| 10 | +#define BOOST_LOCALE_NO_LIB |
| 11 | +#include <boost/locale/encoding.hpp> |
| 12 | +#include <string> |
| 13 | +#include <iostream> |
| 14 | + |
| 15 | +/** Synopsis |
| 16 | +* |
| 17 | +* Test for Utf8 support in the asynchronous connection header parser |
| 18 | +* -------------------------------------------- |
| 19 | +* |
| 20 | +* This test checks for Utf8 support in the header parser |
| 21 | +* for asynchronous connection |
| 22 | +* |
| 23 | +*/ |
| 24 | + |
| 25 | +namespace tags = boost::network::tags; |
| 26 | +namespace logic = boost::logic; |
| 27 | +namespace fusion = boost::fusion; |
| 28 | +using namespace boost::network::http; |
| 29 | + |
| 30 | +BOOST_AUTO_TEST_CASE(async_connection_parse_headers) { |
| 31 | + std::wstring utf16_test_name = L"R\u016bdolfs"; |
| 32 | + request_header_narrow utf8_header = { "X-Utf8-Test-Header", boost::locale::conv::utf_to_utf<char>(utf16_test_name) }; |
| 33 | + std::string valid_http_request; |
| 34 | + valid_http_request.append(utf8_header.name).append(": ").append(utf8_header.value).append("\r\n\r\n"); |
| 35 | + std::vector<request_header_narrow> headers; |
| 36 | + parse_headers(valid_http_request, headers); |
| 37 | + std::vector<request_header_narrow>::iterator header_iterator = headers.begin(); |
| 38 | + for(; header_iterator != headers.end(); ++ header_iterator) |
| 39 | + { |
| 40 | + if (header_iterator->name == utf8_header.name && header_iterator->value == utf8_header.value) |
| 41 | + break; |
| 42 | + } |
| 43 | + std::wstring utf16_test_name_from_header = boost::locale::conv::utf_to_utf<wchar_t>(header_iterator->value); |
| 44 | + BOOST_CHECK(header_iterator != headers.end()); |
| 45 | + BOOST_CHECK(utf16_test_name_from_header == utf16_test_name); |
| 46 | + std::cout << "utf8 header parsed, name: " << header_iterator->name << ", value: " << header_iterator->value; |
| 47 | +} |
0 commit comments