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 from1 commit
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
NextNext commit
Support Utf8 characters in the asynchronous connection http header na…
…me/value parser grammar
  • Loading branch information
Rudolfs Bundulis committedDec 3, 2013
commitceb1eb2f4485467e665a6b204d5d535eb50c092f
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
42 changes: 42 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,42 @@
// Copyright 2010 Dean Michael Berris.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

So technically, this isn't my copyright as you're the author of this code. Please update properly.

// 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>
#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) {
request_header_narrow utf8_header = { "X-Utf8-Test-Header", "R\uc5abdolfs" };
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 utf8_header_iterator = std::find_if(headers.begin(), headers.end(), [&utf8_header, &utf8_header_iterator](request_header_narrow& header)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Unfortunately, 0.11.0 can't use C++11 features -- we reserve any C++11 support for 1.x releases (on master). Can you make this work without C++11 language support?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ahh yeah, sure, i'll rewrite that, sorry that i didn't take that into
account

2013/12/4 Dean Michael Berrisnotifications@github.com

In libs/network/test/http/server_header_parser_test.cpp:

+* 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) {

  • request_header_narrow utf8_header = { "X-Utf8-Test-Header", "R\uc5abdolfs" };
  • 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 utf8_header_iterator = std::find_if(headers.begin(), headers.end(), [&utf8_header, &utf8_header_iterator](request_header_narrow& header)

Unfortunately, 0.11.0 can't use C++11 features -- we reserve any C++11
support for 1.x releases (on master). Can you make this work without C++11
language support?


Reply to this email directly or view it on GitHubhttps://github.com//pull/341/files#r8084812
.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

hi,

sorry for the mess with the PR's, first time and still getting familiar
with how this works, didn't expect that the commit would be added
automatically:D Ok i fixed the test case, works on VS2008 now too, and
makes more sense since at lest the wstring is now readable. I hope the fix
for the status code that i couldn't live without since it fixes compilation
is not an issue:)

2013/12/4 Rûdolfs Bundulisrudolfs.bundulis@gmail.com

ahh yeah, sure, i'll rewrite that, sorry that i didn't take that into
account

2013/12/4 Dean Michael Berrisnotifications@github.com

In libs/network/test/http/server_header_parser_test.cpp:

+* 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) {

  • request_header_narrow utf8_header = { "X-Utf8-Test-Header", "R\uc5abdolfs" };
  • 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 utf8_header_iterator = std::find_if(headers.begin(), headers.end(), [&utf8_header, &utf8_header_iterator](request_header_narrow& header)

Unfortunately, 0.11.0 can't use C++11 features -- we reserve any C++11
support for 1.x releases (on master). Can you make this work without C++11
language support?

Reply to this email directly or view it on GitHubhttps://github.com//pull/341/files#r8084812
.

{
if (header.name == utf8_header.name && header.value == utf8_header.value)
return true;
return false;
});
BOOST_CHECK(utf8_header_iterator != headers.end());
std::cout << "utf8 header parsed, name: " << utf8_header_iterator->name << ", value: " << utf8_header_iterator->value << std::endl;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please add a newline at the end of the file.


[8]ページ先頭

©2009-2025 Movatter.jp