From 928e7139a3effc771857180d5ec2c8e7f63d85b1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 22 Jan 2013 20:43:10 -0800 Subject: [PATCH] Part of the flash policy code. --- src/cpp/websocketpp/src/roles/server.hpp | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cpp/websocketpp/src/roles/server.hpp b/src/cpp/websocketpp/src/roles/server.hpp index 270a478a0..754f4f6b6 100644 --- a/src/cpp/websocketpp/src/roles/server.hpp +++ b/src/cpp/websocketpp/src/roles/server.hpp @@ -53,6 +53,32 @@ namespace websocketpp { +typedef boost::asio::buffers_iterator bufIterator; + +static std::pair match_header(bufIterator begin, bufIterator end) +{ + // Do we have a complete HTTP request + const std::string header_match = "\r\n\r\n"; + bufIterator it = std::search(begin, end, header_match.begin(), header_match.end()); + if (it != end) + return std::make_pair(it, true); + + // If we don't have a flash policy request, we're done + const std::string flash_match = ""; + it = std::search(begin, end, flash_match.begin(), flash_match.end()); + if (it == end) + return std::make_pair(end, false); + + // If we have a line ending before the flash policy request, treat as http + const std::string eol_match = "\r\n"; + bufIterator it2 = std::search(begin, end, eol_match.begin(), eol_match.end()); + if ((it2 != end) || (it < it2)) + return std::make_pair(end, false); + + // Treat as flash policy request + return std::make_pair(it, true); +} + // Forward declarations template struct endpoint_traits; @@ -517,7 +543,7 @@ void server::connection::async_init() { boost::asio::async_read_until( m_connection.get_socket(), m_connection.buffer(), - "\r\n\r\n", + match_header, m_connection.get_strand().wrap(boost::bind( &type::handle_read_request, m_connection.shared_from_this(),