2 * Copyright 2013 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.
20 #include "folly/String.h"
25 * Class representing a URI.
27 * Consider http://www.facebook.com/foo/bar?key=foo#anchor
29 * The URI is broken down into its parts: scheme ("http"), authority
30 * (ie. host and port, in most cases: "www.facebook.com"), path
31 * ("/foo/bar"), query ("key=foo") and fragment ("anchor"). The scheme is
34 * If this Uri represents a URL, note that, to prevent ambiguity, the component
35 * parts are NOT percent-decoded; you should do this yourself with
36 * uriUnescape() (for the authority and path) and uriUnescape(...,
37 * UriEscapeMode::QUERY) (for the query, but probably only after splitting at
38 * '&' to identify the individual parameters).
43 * Parse a Uri from a string. Throws std::invalid_argument on parse error.
45 explicit Uri(StringPiece str);
47 const fbstring& scheme() const { return scheme_; }
48 const fbstring& username() const { return username_; }
49 const fbstring& password() const { return password_; }
50 const fbstring& host() const { return host_; }
51 uint32_t port() const { return port_; }
52 const fbstring& path() const { return path_; }
53 const fbstring& query() const { return query_; }
54 const fbstring& fragment() const { return fragment_; }
56 template <class String>
57 String toString() const;
59 std::string str() const { return toString<std::string>(); }
60 fbstring fbstr() const { return toString<fbstring>(); }
75 #include "folly/Uri-inl.h"
77 #endif /* FOLLY_URI_H_ */