Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support Utf8 characters in the asynchronous connection header parser#341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deanberris merged 4 commits intocpp-netlib:0.11-develfromrubu:0.11-devel
Dec 5, 2013
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletionsboost/network/protocol/http/server/impl/parsers.ipp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#ifndef SERVER_REQUEST_PARSERS_IMPL_UW3PM6V6
#define SERVER_REQUEST_PARSERS_IMPL_UW3PM6V6

#define BOOST_SPIRIT_UNICODE
#include <boost/spirit/include/qi.hpp>

// Copyright 2010 Dean Michael Berris.
Expand All@@ -20,6 +21,26 @@
#endif
#include <vector>

namespace boost { namespace spirit { namespace traits {

typedef std::basic_string<uint32_t> u32_string;

template <> // <typename Attrib, typename T, typename Enable>
struct assign_to_container_from_value<std::string, u32_string, void>
{
static void call(u32_string const& val, std::string& attr) {
u32_to_u8_iterator<u32_string::const_iterator> begin(val.begin()), end(val.end());
for(; begin != end; ++begin)
attr += *begin;
}
};

} // namespace traits

} // namespace spirit

} // namespace boost

namespace boost { namespace network { namespace http {

BOOST_NETWORK_INLINE void parse_version(std::string const & partial_parsed, fusion::tuple<uint8_t,uint8_t> & version_pair) {
Expand All@@ -37,12 +58,13 @@ namespace boost { namespace network { namespace http {

BOOST_NETWORK_INLINE void parse_headers(std::string const & input, std::vector<request_header_narrow> & container) {
using namespace boost::spirit::qi;
u8_to_u32_iterator<std::string::const_iterator> begin(input.begin()), end(input.end());
parse(
input.begin(), input.end(),
begin,end,
*(
+(alnum|(punct-':'))
as<boost::spirit::traits::u32_string>()[+(alnum|(punct-':'))]
>> lit(": ")
>> +((alnum|space|punct) - '\r' - '\n')
>>as<boost::spirit::traits::u32_string>()[+((unicode::alnum|space|punct) - '\r' - '\n')]
>> lit("\r\n")
)
>> lit("\r\n")
Expand Down
1 change: 1 addition & 0 deletionslibs/network/test/http/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,6 +62,7 @@ if (Boost_FOUND)
set ( SERVER_API_TESTS
server_constructor_test
server_async_run_stop_concurrency
server_header_parser_test
)
foreach ( test ${SERVER_API_TESTS} )
add_executable(cpp-netlib-http-${test} ${test}.cpp)
Expand Down
47 changes: 47 additions & 0 deletionslibs/network/test/http/server_header_parser_test.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
// Copyright 2013 Rudolfs Bundulis
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#define BOOST_TEST_MODULE HTTP Server Header Parser Test
#include <boost/network/protocol/http/server.hpp>
#include <boost/config/warning_disable.hpp>
#include <boost/test/unit_test.hpp>
#define BOOST_LOCALE_NO_LIB
#include <boost/locale/encoding.hpp>
#include <string>
#include <iostream>

/** Synopsis
*
* Test for Utf8 support in the asynchronous connection header parser
* --------------------------------------------
*
* This test checks for Utf8 support in the header parser
* for asynchronous connection
*
*/

namespace tags = boost::network::tags;
namespace logic = boost::logic;
namespace fusion = boost::fusion;
using namespace boost::network::http;

BOOST_AUTO_TEST_CASE(async_connection_parse_headers) {
std::wstring utf16_test_name = L"R\u016bdolfs";
request_header_narrow utf8_header = { "X-Utf8-Test-Header", boost::locale::conv::utf_to_utf<char>(utf16_test_name) };
std::string valid_http_request;
valid_http_request.append(utf8_header.name).append(": ").append(utf8_header.value).append("\r\n\r\n");
std::vector<request_header_narrow> headers;
parse_headers(valid_http_request, headers);
std::vector<request_header_narrow>::iterator header_iterator = headers.begin();
for(; header_iterator != headers.end(); ++ header_iterator)
{
if (header_iterator->name == utf8_header.name && header_iterator->value == utf8_header.value)
break;
}
std::wstring utf16_test_name_from_header = boost::locale::conv::utf_to_utf<wchar_t>(header_iterator->value);
BOOST_CHECK(header_iterator != headers.end());
BOOST_CHECK(utf16_test_name_from_header == utf16_test_name);
std::cout << "utf8 header parsed, name: " << header_iterator->name << ", value: " << header_iterator->value;
}

[8]ページ先頭

©2009-2025 Movatter.jp