//------------------------------------------------------------------------------ /* This file is part of Beast: https://github.com/vinniefalco/Beast Copyright 2013, Vinnie Falco Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #include namespace beast { URL::URL ( std::string scheme_, std::string host_, std::uint16_t port_, std::string port_string_, std::string path_, std::string query_, std::string fragment_, std::string userinfo_) : m_scheme (scheme_) , m_host (host_) , m_port (port_) , m_port_string (port_string_) , m_path (path_) , m_query (query_) , m_fragment (fragment_) , m_userinfo (userinfo_) { } //------------------------------------------------------------------------------ bool URL::empty () const { return m_scheme.empty (); } std::string const& URL::scheme () const { return m_scheme; } std::string const& URL::host () const { return m_host; } std::string const& URL::port_string () const { return m_port_string; } std::uint16_t URL::port () const { return m_port; } std::string const& URL::path () const { return m_path; } std::string const& URL::query () const { return m_query; } std::string const& URL::fragment () const { return m_fragment; } std::string const& URL::userinfo () const { return m_userinfo; } //------------------------------------------------------------------------------ std::pair parse_URL(std::string const& url) { std::size_t const buflen (url.size ()); char const* const buf (url.c_str ()); joyent::http_parser_url parser; if (joyent::http_parser_parse_url (buf, buflen, false, &parser) != 0) return std::make_pair (false, URL{}); std::string scheme; std::string host; std::uint16_t port (0); std::string port_string; std::string path; std::string query; std::string fragment; std::string userinfo; if ((parser.field_set & (1<