blob: 4b057db3b3a2fc037b40f7953d5894455f8a43b3 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
vasilvv872e7a32019-03-12 16:42:44 -07008#include <string>
9
QUICHE teama6ef0a62019-03-07 20:34:33 -050010#include "url/gurl.h"
11#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
QUICHE team5015e2e2019-12-11 09:38:06 -080012#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050013
14namespace quic {
15
16// A utility class that wraps GURL.
17class 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 team5015e2e2019-12-11 09:38:06 -080027 explicit QuicUrl(quiche::QuicheStringPiece url);
QUICHE teama6ef0a62019-03-07 20:34:33 -050028
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 team5015e2e2019-12-11 09:38:06 -080031 QuicUrl(quiche::QuicheStringPiece url,
32 quiche::QuicheStringPiece default_scheme);
QUICHE teama6ef0a62019-03-07 20:34:33 -050033
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.
vasilvvc48c8712019-03-11 13:38:16 -070039 std::string ToString() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050040
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.
vasilvvc48c8712019-03-11 13:38:16 -070046 std::string HostPort() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050047
48 // Returns a string assembles path, parameters and query.
vasilvvc48c8712019-03-11 13:38:16 -070049 std::string PathParamsQuery() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050050
vasilvvc48c8712019-03-11 13:38:16 -070051 std::string scheme() const;
52 std::string host() const;
53 std::string path() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050054 uint16_t port() const;
55
56 private:
57 GURL url_;
58};
59
60} // namespace quic
61
62#endif // QUICHE_QUIC_TOOLS_QUIC_URL_H_