예제 #1
0
inline
boost::optional<unsigned short> port_us(const uri &uri_) {
    std::string port = uri_.port();
    return (port.empty())?
        boost::optional<unsigned short>() :
        boost::optional<unsigned short>(boost::lexical_cast<unsigned short>(port));
}
예제 #2
0
파일: uri.cpp 프로젝트: PKRoma/cpprestsdk
bool uri::operator == (const uri &other) const
{
    // Each individual URI component must be decoded before performing comparison.
    // TFS # 375865

    if (this->is_empty() && other.is_empty())
    {
        return true;
    }
    else if (this->is_empty() || other.is_empty())
    {
        return false;
    }
    else if (this->scheme() != other.scheme())
    {
        // scheme is canonicalized to lowercase
        return false;
    }
    else if(uri::decode(this->user_info()) != uri::decode(other.user_info()))
    {
        return false;
    }
    else if (uri::decode(this->host()) != uri::decode(other.host()))
    {
        // host is canonicalized to lowercase
        return false;
    }
    else if (this->port() != other.port())
    {
        return false;
    }
    else if (uri::decode(this->path()) != uri::decode(other.path()))
    {
        return false;
    }
    else if (uri::decode(this->query()) != uri::decode(other.query()))
    {
        return false;
    }
    else if (uri::decode(this->fragment()) != uri::decode(other.fragment()))
    {
        return false;
    }

    return true;
}
예제 #3
0
inline
std::string authority(const uri &uri_) {
    std::string user_info(uri_.user_info());
	std::string host(uri_.host());
    std::string port(uri_.port());
	std::string authority;
	if (!boost::empty(user_info))
	{
		std::copy(boost::begin(user_info), boost::end(user_info), std::back_inserter(authority));
		authority.push_back('@');
	}
	if (!boost::empty(host))
	{
		std::copy(boost::begin(host), boost::end(host), std::back_inserter(authority));
	}
	if (!boost::empty(port))
	{
		authority.push_back(':');
		std::copy(boost::begin(port), boost::end(port), std::back_inserter(authority));
	}
	return authority;
}
예제 #4
0
  const std::string pfi_expected = "ピーFI";
  const std::string pfi_actual = net::uri_decode("%E3%83%94%E3%83%BcFI");
  EXPECT_TRUE(equal_percent_encoded_string(pfi_expected, pfi_actual));
}

TEST(uri, class)
{
  using pfi::network::uri;

  uri pfi("http://preferred.jp/product/sedue/");
  EXPECT_EQ("http", pfi.scheme());
  EXPECT_EQ("preferred.jp", pfi.authority());
  EXPECT_TRUE(pfi.userinfo().empty());
  EXPECT_EQ("preferred.jp", pfi.host());
  EXPECT_TRUE(pfi.port().empty());
  EXPECT_EQ("/product/sedue/", pfi.path());
  EXPECT_TRUE(pfi.query().empty());
  EXPECT_TRUE(pfi.fragment().empty());

  uri complex("http://*****:*****@a.com:80/aoeu/htns?q=1234&r=5678#n42");
  EXPECT_EQ("http", complex.scheme());
  EXPECT_EQ("user:[email protected]:80", complex.authority());
  EXPECT_EQ("user:pass", complex.userinfo());
  EXPECT_EQ("a.com", complex.host());
  EXPECT_EQ("80", complex.port());
  EXPECT_EQ("/aoeu/htns", complex.path());
  EXPECT_EQ("q=1234&r=5678", complex.query());
  EXPECT_EQ("n42", complex.fragment());

  uri ipv6("http://[2001:0DB8:0000:CD30:0123:4567:89AB:CDEF]/");
예제 #5
0
inline
std::string port(const uri &uri_) {
    return uri_.port();
}