2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #error This file may only be included from folly/Uri.h
24 #include <folly/Conv.h>
25 #include <folly/hash/Hash.h>
29 namespace uri_detail {
31 using UriTuple = std::tuple<
41 inline UriTuple as_tuple(const folly::Uri& k) {
53 } // namespace uri_detail
55 template <class String>
56 String Uri::toString() const {
59 toAppend(scheme_, "://", &str);
60 if (!password_.empty()) {
61 toAppend(username_, ":", password_, "@", &str);
62 } else if (!username_.empty()) {
63 toAppend(username_, "@", &str);
65 toAppend(host_, &str);
67 toAppend(":", port_, &str);
70 toAppend(scheme_, ":", &str);
72 toAppend(path_, &str);
73 if (!query_.empty()) {
74 toAppend("?", query_, &str);
76 if (!fragment_.empty()) {
77 toAppend("#", fragment_, &str);
87 struct hash<folly::Uri> {
88 std::size_t operator()(const folly::Uri& k) const {
89 return std::hash<folly::uri_detail::UriTuple>{}(
90 folly::uri_detail::as_tuple(k));
95 struct equal_to<folly::Uri> {
96 bool operator()(const folly::Uri& a, const folly::Uri& b) const {
97 return folly::uri_detail::as_tuple(a) == folly::uri_detail::as_tuple(b);