1 // Copyright 2013 Rudolfs Bundulis
2 // Copyright 2016 Google, Inc.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #include <gtest/gtest.h>
8 #include <boost/network/protocol/http/server.hpp>
9 #include <boost/config/warning_disable.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 
TEST(ServerHeaderParserTest,ParseHeaders)30 TEST(ServerHeaderParserTest, ParseHeaders) {
31   std::wstring utf16_test_name = L"R\u016bdolfs";
32   request_header_narrow utf8_header = {
33       "X-Utf8-Test-Header",
34       boost::locale::conv::utf_to_utf<char>(utf16_test_name)};
35   std::string valid_http_request;
36   valid_http_request.append(utf8_header.name)
37       .append(": ")
38       .append(utf8_header.value)
39       .append("\r\n\r\n");
40   std::vector<request_header_narrow> headers;
41   parse_headers(valid_http_request, headers);
42   std::vector<request_header_narrow>::iterator header_iterator =
43       headers.begin();
44   for (; header_iterator != headers.end(); ++header_iterator) {
45     if (header_iterator->name == utf8_header.name &&
46         header_iterator->value == utf8_header.value)
47       break;
48   }
49   std::wstring utf16_test_name_from_header =
50       boost::locale::conv::utf_to_utf<wchar_t>(header_iterator->value);
51   EXPECT_TRUE(header_iterator != headers.end());
52   EXPECT_TRUE(utf16_test_name_from_header == utf16_test_name);
53   std::cout << "utf8 header parsed, name: " << header_iterator->name
54             << ", value: " << header_iterator->value;
55 }
56