1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef QUICHE_QUIC_TOOLS_QUIC_URL_H_ 6 #define QUICHE_QUIC_TOOLS_QUIC_URL_H_ 7 8 #include <string> 9 10 #include "absl/strings/string_view.h" 11 #include "quiche/quic/platform/api/quic_export.h" 12 #include "quiche/common/platform/api/quiche_googleurl.h" 13 14 namespace quic { 15 16 // A utility class that wraps GURL. 17 class QuicUrl { 18 public: 19 // Constructs an empty QuicUrl. 20 QuicUrl() = default; 21 22 // Constructs a QuicUrl from the url string |url|. 23 // 24 // NOTE: If |url| doesn't have a scheme, it will have an empty scheme 25 // field. If that's not what you want, use the QuicUrlImpl(url, 26 // default_scheme) form below. 27 explicit QuicUrl(absl::string_view url); 28 29 // Constructs a QuicUrlImpl from |url|, assuming that the scheme for the URL 30 // is |default_scheme| if there is no scheme specified in |url|. 31 QuicUrl(absl::string_view url, absl::string_view default_scheme); 32 33 // Returns false if the URL is not valid. 34 bool IsValid() const; 35 36 // Returns full text of the QuicUrl if it is valid. Return empty string 37 // otherwise. 38 std::string ToString() const; 39 40 // Returns host:port. 41 // If the host is empty, it will return an empty string. 42 // If the host is an IPv6 address, it will be bracketed. 43 // If port is not present or is equal to default_port of scheme (e.g., port 44 // 80 for HTTP), it won't be returned. 45 std::string HostPort() const; 46 47 // Returns a string assembles path, parameters and query. 48 std::string PathParamsQuery() const; 49 50 std::string scheme() const; 51 std::string host() const; 52 std::string path() const; 53 uint16_t port() const; 54 55 private: 56 GURL url_; 57 }; 58 59 } // namespace quic 60 61 #endif // QUICHE_QUIC_TOOLS_QUIC_URL_H_ 62