Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
google_url.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
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
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
19 
20 #ifndef PAGESPEED_KERNEL_HTTP_GOOGLE_URL_H_
21 #define PAGESPEED_KERNEL_HTTP_GOOGLE_URL_H_
22 
23 #include <cstddef>
24 
28 
29 
30 #include "third_party/chromium/src/googleurl/src/gurl.h"
31 #include "third_party/chromium/src/googleurl/src/url_parse.h"
32 #include "third_party/chromium/src/googleurl/src/url_util.h"
33 
34 namespace net_instaweb {
35 
37 
38 namespace url {
39 
40 using url_canon::Replacements;
41 using url_parse::PORT_UNSPECIFIED;
42 using url_parse::PORT_INVALID;
43 using url_parse::Component;
44 using url_parse::Parsed;
45 using url_util::Initialize;
46 using url_util::Shutdown;
47 
48 };
49 
50 
56 };
57 
58 class GoogleUrl {
59  public:
60  explicit GoogleUrl(const GoogleString& spec);
61  explicit GoogleUrl(StringPiece sp);
62  explicit GoogleUrl(const char* str);
65  GoogleUrl(const GoogleUrl& base, const GoogleString& relative);
66  GoogleUrl(const GoogleUrl& base, StringPiece relative);
67  GoogleUrl(const GoogleUrl& base, const char* relative);
68  GoogleUrl();
69 
70  void Swap(GoogleUrl* google_url);
71 
72  bool Reset(StringPiece new_url);
73  bool Reset(const GoogleUrl& new_url);
74  bool Reset(const GoogleUrl& base, const GoogleString& relative);
75  bool Reset(const GoogleUrl& base, StringPiece relative);
76  bool Reset(const GoogleUrl& base, const char* relative);
77 
79  void Clear();
80 
82  bool IsWebValid() const;
84  bool IsWebOrDataValid() const;
87  bool IsAnyValid() const;
88 
94  GoogleUrl* CopyAndAddQueryParam(StringPiece unescaped_name,
95  StringPiece unescaped_value) const;
99  StringPiece escaped_name, StringPiece escaped_value) const;
100 
103  StringPiece AllExceptQuery() const;
104 
110  StringPiece AllAfterQuery() const;
111 
115  StringPiece AllExceptLeaf() const;
116 
119  StringPiece LeafWithQuery() const;
120 
123  StringPiece LeafSansQuery() const;
124 
128  StringPiece PathAndLeaf() const;
129 
134  StringPiece PathSansLeaf() const;
135 
138  StringPiece PathSansQuery() const;
139 
144  StringPiece NetPath() const;
145 
149 
150  StringPiece Host() const;
151 
154  StringPiece HostAndPort() const;
155 
159  StringPiece Origin() const;
160 
164  StringPiece Query() const;
165 
167  StringPiece Scheme() const;
168 
170  StringPiece Spec() const;
171 
173  StringPiece UncheckedSpec() const;
174 
176  const char* spec_c_str() const {
177  return gurl_.possibly_invalid_spec().c_str();
178  }
179 
180  int IntPort() const { return gurl_.IntPort(); }
181 
183  int EffectiveIntPort() const { return gurl_.EffectiveIntPort(); }
184 
187  static int DefaultPortForScheme(StringPiece scheme);
188 
189  bool is_empty() const { return gurl_.is_empty(); }
190  bool has_scheme() const { return gurl_.has_scheme(); }
191  bool has_path() const { return gurl_.has_path(); }
192  bool has_query() const { return gurl_.has_query(); }
193 
194  bool SchemeIs(const char* lower_ascii_scheme) const {
195  return gurl_.SchemeIs(lower_ascii_scheme);
196  }
197 
200  bool SchemeIs(StringPiece lower_ascii_scheme) const {
201  return gurl_.SchemeIs(lower_ascii_scheme.as_string().c_str());
202  }
203 
205  static UrlRelativity FindRelativity(StringPiece url);
206 
212  StringPiece Relativize(UrlRelativity url_relativity,
213  const GoogleUrl& base_url) const;
214 
216  bool operator==(const GoogleUrl& other) const {
217  return gurl_ == other.gurl_;
218  }
219  bool operator!=(const GoogleUrl& other) const {
220  return gurl_ != other.gurl_;
221  }
222 
231  static GoogleString UnescapeQueryParam(StringPiece escaped) {
232  return UnescapeHelper(escaped, true);
233  }
234 
237  static GoogleString UnescapeIgnorePlus(StringPiece escaped) {
238  return UnescapeHelper(escaped, false);
239  }
240 
244  static GoogleString EscapeQueryParam(StringPiece unescaped);
245 
253  static GoogleString Sanitize(StringPiece url);
254 
258  static GoogleString CanonicalizePath(StringPiece path);
259 
260  private:
262  static const size_t npos;
263 
264  static const char kReservedChars[];
265  static bool IsReservedChar(char c);
266 
267  explicit GoogleUrl(const GURL& gurl);
268  void Init();
269 
270  static size_t LeafEndPosition(const GURL& gurl);
271  static size_t LeafStartPosition(const GURL& gurl);
272  static size_t PathStartPosition(const GURL& gurl);
273  size_t LeafEndPosition() const;
274  size_t LeafStartPosition() const;
275  size_t PathStartPosition() const;
276  static GoogleString UnescapeHelper(StringPiece escaped,
277  bool convert_plus_to_space);
278 
280  inline bool ResolveHelper(const GURL& base, const std::string& path_and_leaf);
281 
282  GURL gurl_;
283  bool is_web_valid_;
284  bool is_web_or_data_valid_;
285 
286 
287 };
288 
289 }
290 
291 
292 #endif
class GoogleUrl
Definition: google_url.h:58
StringPiece Query() const
bool IsWebOrDataValid() const
Also allows data: URLs.
bool IsAnyValid() const
StringPiece LeafWithQuery() const
static UrlRelativity FindRelativity(StringPiece url)
Find out how relative the URL string is.
//example.com/foo/bar/file.ext?k=v::f
Definition: google_url.h:53
static int DefaultPortForScheme(StringPiece scheme)
StringPiece HostAndPort() const
GoogleUrl * CopyAndAddEscapedQueryParam(StringPiece escaped_name, StringPiece escaped_value) const
bool SchemeIs(StringPiece lower_ascii_scheme) const
Definition: google_url.h:200
bar/file.ext?k=v::f
Definition: google_url.h:55
StringPiece Origin() const
StringPiece PathSansQuery() const
GoogleUrl * CopyAndAddQueryParam(StringPiece unescaped_name, StringPiece unescaped_value) const
StringPiece Spec() const
It is illegal to call this for invalid urls (check IsWebValid() first).
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static GoogleString EscapeQueryParam(StringPiece unescaped)
StringPiece PathAndLeaf() const
StringPiece Relativize(UrlRelativity url_relativity, const GoogleUrl &base_url) const
StringPiece NetPath() const
StringPiece AllAfterQuery() const
void Clear()
Resets this URL to be invalid.
bool IsWebValid() const
Is a valid web (HTTP or HTTPS) URL. Most users will want this.
/foo/bar/file.ext?k=v::f
Definition: google_url.h:54
StringPiece Scheme() const
Returns scheme of stored url.
StringPiece AllExceptQuery() const
bool operator==(const GoogleUrl &other) const
Defiant equality operator!
Definition: google_url.h:216
StringPiece UncheckedSpec() const
Returns gurl_.spec_ without checking to see if it's valid or empty.
UrlRelativity
namespace url
Definition: google_url.h:51
static GoogleString Sanitize(StringPiece url)
StringPiece AllExceptLeaf() const
static GoogleString UnescapeIgnorePlus(StringPiece escaped)
Definition: google_url.h:237
static GoogleString UnescapeQueryParam(StringPiece escaped)
Definition: google_url.h:231
StringPiece LeafSansQuery() const
StringPiece PathSansLeaf() const
const char * spec_c_str() const
This method is primarily for printf purposes.
Definition: google_url.h:176
int EffectiveIntPort() const
Returns the effective port number, which is dependent on the scheme.
Definition: google_url.h:183
static GoogleString CanonicalizePath(StringPiece path)
GoogleString ExtractFileName() const
http://example.com/foo/bar/file.ext?k=v#f
Definition: google_url.h:52