QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include "url/gurl.h" |
| 11 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
QUICHE team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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. |
QUICHE team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame] | 27 | explicit QuicUrl(quiche::QuicheStringPiece url); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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|. |
QUICHE team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame] | 31 | QuicUrl(quiche::QuicheStringPiece url, |
| 32 | quiche::QuicheStringPiece default_scheme); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 33 | |
| 34 | // Returns false if the URL is not valid. |
| 35 | bool IsValid() const; |
| 36 | |
| 37 | // Returns full text of the QuicUrl if it is valid. Return empty string |
| 38 | // otherwise. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 39 | std::string ToString() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 40 | |
| 41 | // Returns host:port. |
| 42 | // If the host is empty, it will return an empty string. |
| 43 | // If the host is an IPv6 address, it will be bracketed. |
| 44 | // If port is not present or is equal to default_port of scheme (e.g., port |
| 45 | // 80 for HTTP), it won't be returned. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 46 | std::string HostPort() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 47 | |
| 48 | // Returns a string assembles path, parameters and query. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 49 | std::string PathParamsQuery() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 50 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 51 | std::string scheme() const; |
| 52 | std::string host() const; |
| 53 | std::string path() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 54 | uint16_t port() const; |
| 55 | |
| 56 | private: |
| 57 | GURL url_; |
| 58 | }; |
| 59 | |
| 60 | } // namespace quic |
| 61 | |
| 62 | #endif // QUICHE_QUIC_TOOLS_QUIC_URL_H_ |