Пример #1
0
//=============================================================================
bool Uri::operator==(const Uri& v) const
{
  return get_scheme() == v.get_scheme() &&
    get_host() == v.get_host() &&
    get_port() == v.get_port() &&
    get_path() == v.get_path() &&
    get_query() == v.get_query();
}
Пример #2
0
//=============================================================================
bool Uri::operator!=(const Uri& v) const
{
  return get_scheme() != v.get_scheme() ||
    get_host() != v.get_host() ||
    get_port() != v.get_port() ||
    get_path() != v.get_path() ||
    get_query() != v.get_query();
}
Пример #3
0
 Request::Request( const Uri& value ) : m_pimpl( new detail::RequestImpl )
 {
     m_pimpl->m_uri = make_shared< Uri >( value );
     m_pimpl->m_path = value.get_path( );
     m_pimpl->m_port = value.get_port( );
     m_pimpl->m_host = value.get_authority( );
     m_pimpl->m_query_parameters = value.get_query_parameters( );
     m_pimpl->m_protocol = String::uppercase( value.get_scheme( ) );
     
     if ( m_pimpl->m_path.empty( ) )
     {
         m_pimpl->m_path = "/";
     }
     
     if ( m_pimpl->m_port == 0 )
     {
         m_pimpl->m_port = ( m_pimpl->m_protocol == "HTTPS" ) ? 443 : 80;
     }
 }
Пример #4
0
//External Includes
#include <catch.hpp>

//System Namespaces
using std::string;
using std::invalid_argument;

//Project Namespaces
using restbed::Uri;

//External Namespaces

TEST_CASE( "default constructor", "[uri]" )
{
    Uri uri( "http://crowhurst.ben:[email protected]:80/resources/index.html?q=bear&b=cubs#frag1" );
    REQUIRE( uri.get_port( ) == 80 );
    REQUIRE( uri.get_path( ) == "/resources/index.html" );
    REQUIRE( uri.get_query( ) == "q=bear&b=cubs" );
    REQUIRE( uri.get_scheme( ) == "http" );
    REQUIRE( uri.get_fragment( ) == "frag1" );
    REQUIRE( uri.get_username( ) == "crowhurst.ben" );
    REQUIRE( uri.get_password( ) == "ASDFFDSA1234" );
    REQUIRE( uri.get_authority( ) == "code.google.com" );
    
    const string value = uri.to_string( );
    REQUIRE( value == "http://crowhurst.ben:[email protected]:80/resources/index.html?q=bear&b=cubs#frag1" );
}

TEST_CASE( "ipv4 constructor", "[uri]" )
{
    Uri uri( "http://*****:*****@127.1.1.1:80/resources/index.html?q=bear&b=cubs#frag1" );
//System Namespaces
using std::string;
using std::multimap;

//Project Namespaces
using namespace restbed;

//External Namespaces

TEST_CASE( "uri fails to handle file scheme relative paths", "[uri]" )
{
    multimap< string, string > expectation;
    
    Uri relative( "file://certs/server.key", true );
    REQUIRE( relative.get_port( ) == 0 );
    REQUIRE( relative.get_path( ) == "certs/server.key" );
    REQUIRE( relative.get_query( ) == "" );
    REQUIRE( relative.get_scheme( ) == "file" );
    REQUIRE( relative.get_fragment( ) == "" );
    REQUIRE( relative.get_username( ) == "" );
    REQUIRE( relative.get_password( ) == "" );
    REQUIRE( relative.get_authority( ) == "" );
    REQUIRE( relative.is_relative( ) == true );
    REQUIRE( relative.is_absolute( ) == false );
    REQUIRE( relative.to_string( ) == "file://certs/server.key" );
    REQUIRE( relative.get_query_parameters( ) == expectation );
    
    Uri absolute( "file:///certs/server.key" );
    REQUIRE( absolute.get_port( ) == 0 );
    REQUIRE( absolute.get_path( ) == "/certs/server.key" );