diff --git a/changelog.md b/changelog.md index 4a5826c53f..ddff19e467 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,5 @@ HEAD +- Adds URI method to extract query string from URI. - Numerous performance improvements. Including: tuned default buffer sizes based on profiling, caching of handler binding for async reads/writes, non-malloc allocators for read/write handlers, disabling of a number of questionably diff --git a/test/utility/uri.cpp b/test/utility/uri.cpp index e88a8d92b1..fa3ad04d96 100644 --- a/test/utility/uri.cpp +++ b/test/utility/uri.cpp @@ -43,6 +43,7 @@ BOOST_AUTO_TEST_CASE( uri_valid ) { BOOST_CHECK_EQUAL( uri.get_host(), "localhost"); BOOST_CHECK_EQUAL( uri.get_port(), 9000 ); BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" ); + BOOST_CHECK_EQUAL( uri.get_query(), "" ); } // Test a regular valid ws URI @@ -201,6 +202,7 @@ BOOST_AUTO_TEST_CASE( uri_valid_4 ) { BOOST_CHECK_EQUAL( uri.get_host(), "localhost"); BOOST_CHECK_EQUAL( uri.get_port(), 9000 ); BOOST_CHECK_EQUAL( uri.get_resource(), "/chat/foo/bar?foo=bar" ); + BOOST_CHECK_EQUAL( uri.get_query(), "foo=bar" ); } // Valid URI with a mapped v4 ipv6 literal diff --git a/websocketpp/uri.hpp b/websocketpp/uri.hpp index a287fa9f91..5471031a86 100644 --- a/websocketpp/uri.hpp +++ b/websocketpp/uri.hpp @@ -281,16 +281,23 @@ public: s << m_resource; return s.str(); } - - std::string const get_query() const { - std::size_t found = m_resource.find("?"); - if (found > 0) + + /// Return the query portion + /** + * Returns the query portion (after the ?) of the URI or an empty string if + * there is none. + * + * @return query portion of the URI. + */ + std::string get_query() const { + std::size_t found = m_resource.find('?'); + if (found != std::string::npos) { return m_resource.substr(found + 1); - else + } else { return ""; + } } - // get query? // get fragment // hi <3