From 93b75ccc7ddc5345c4a3a021eb08f7f10b21c05d Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 17 Sep 2015 10:09:07 -0400 Subject: [PATCH] Add get_status and get_response methods to connection fixes #465 --- changelog.md | 3 +++ websocketpp/connection.hpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/changelog.md b/changelog.md index 75029c2..2b7b4d4 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,9 @@ HEAD `pass_through` error type. - Improvement: Add a `get_transport_error` method to Asio transport connections to allow retrieving a machine readable native transport error. +- Improvement: Add `connection::get_status` and `connection::get_response` + methods to allow accessing additional information about the HTTP responses + that WebSocket++ sends. #465 Thank you Flow86 for reporting. - Documentation: Adds an example demonstrating the use of external `io_service` - Bug: Fix memory leak when init_asio produces an error. #454 Thank you Mark Grimes for reporting and fixing. diff --git a/websocketpp/connection.hpp b/websocketpp/connection.hpp index 203de6f..0d5bb75 100644 --- a/websocketpp/connection.hpp +++ b/websocketpp/connection.hpp @@ -969,6 +969,18 @@ public: */ std::string const & get_response_header(std::string const & key) const; + /// Get response status code and message + /** + * Gets the response status code + * + * @since 0.7.0 + * + * @return The response status code sent + */ + http::status_code::value get_status() const { + return m_response->get_status(); + } + /// Set response status code and message /** * Sets the response status code to `code` and looks up the corresponding @@ -1076,6 +1088,25 @@ public: return m_request; } + /// Get response object + /** + * Direct access to the HTTP response sent or received as a part of the + * opening handshake. This can be used to call methods of the response + * object that are not part of the standard request API that connection + * wraps. + * + * Note use of this method involves using behavior specific to the + * configured HTTP policy. Such behavior may not work with alternate HTTP + * policies. + * + * @since 0.7.0 + * + * @return A const reference to the raw response object + */ + response_type const & get_response() const { + return m_response; + } + /// Defer HTTP Response until later (Exception free) /** * Used in the http handler to defer the HTTP response for this connection