inline uri::string_type decoded_query(const uri &uri_) { const uri::string_type query = uri_.query(); uri::string_type decoded_query; decode(query, std::back_inserter(decoded_query)); return decoded_query; }
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; }
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]/"); EXPECT_EQ("http", ipv6.scheme()); EXPECT_EQ("[2001:0DB8:0000:CD30:0123:4567:89AB:CDEF]", ipv6.host());
inline std::string query(const uri &uri_) { return uri_.query(); }