OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_auth_cache.h" | 5 #include "net/http/http_auth_cache.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/http/http_util.h" | |
10 | |
11 namespace net { | |
9 | 12 |
10 namespace { | 13 namespace { |
11 | 14 |
12 // Helper to find the containing directory of path. In RFC 2617 this is what | 15 // Helper to find the containing directory of path. In RFC 2617 this is what |
13 // they call the "last symbolic element in the absolute path". | 16 // they call the "last symbolic element in the absolute path". |
14 // Examples: | 17 // Examples: |
15 // "/foo/bar.txt" --> "/foo/" | 18 // "/foo/bar.txt" --> "/foo/" |
16 // "/foo/" --> "/foo/" | 19 // "/foo/" --> "/foo/" |
17 std::string GetParentDirectory(const std::string& path) { | 20 std::string GetParentDirectory(const std::string& path) { |
18 std::string::size_type last_slash = path.rfind("/"); | 21 std::string::size_type last_slash = path.rfind("/"); |
(...skipping 17 matching lines...) Expand all Loading... | |
36 bool IsEnclosingPath(const std::string& container, const std::string& path) { | 39 bool IsEnclosingPath(const std::string& container, const std::string& path) { |
37 DCHECK(container.empty() || *(container.end() - 1) == '/'); | 40 DCHECK(container.empty() || *(container.end() - 1) == '/'); |
38 return ((container.empty() && path.empty()) || | 41 return ((container.empty() && path.empty()) || |
39 (!container.empty() && StartsWithASCII(path, container, true))); | 42 (!container.empty() && StartsWithASCII(path, container, true))); |
40 } | 43 } |
41 | 44 |
42 // Debug helper to check that |origin| arguments are properly formed. | 45 // Debug helper to check that |origin| arguments are properly formed. |
43 void CheckOriginIsValid(const GURL& origin) { | 46 void CheckOriginIsValid(const GURL& origin) { |
44 DCHECK(origin.is_valid()); | 47 DCHECK(origin.is_valid()); |
45 // Note that the scheme may be FTP when we're using a HTTP proxy. | 48 // Note that the scheme may be FTP when we're using a HTTP proxy. |
46 DCHECK(origin.SchemeIsHTTPOrHTTPS() || origin.SchemeIs("ftp")); | 49 DCHECK(origin.SchemeIsHTTPOrHTTPS() || origin.SchemeIs("ftp") || |
50 HttpUtil::SchemeIsWsOrWss(origin)); | |
szym
2013/11/19 02:42:50
Add SchemeIsWSOrWSS to GURL.
Adam Rice
2013/11/19 03:56:44
Done.
| |
47 DCHECK(origin.GetOrigin() == origin); | 51 DCHECK(origin.GetOrigin() == origin); |
48 } | 52 } |
49 | 53 |
50 // Functor used by remove_if. | 54 // Functor used by remove_if. |
51 struct IsEnclosedBy { | 55 struct IsEnclosedBy { |
52 explicit IsEnclosedBy(const std::string& path) : path(path) { } | 56 explicit IsEnclosedBy(const std::string& path) : path(path) { } |
53 bool operator() (const std::string& x) const { | 57 bool operator() (const std::string& x) const { |
54 return IsEnclosingPath(path, x); | 58 return IsEnclosingPath(path, x); |
55 } | 59 } |
56 const std::string& path; | 60 const std::string& path; |
57 }; | 61 }; |
58 | 62 |
59 } // namespace | 63 } // namespace |
60 | 64 |
61 namespace net { | |
62 | |
63 HttpAuthCache::HttpAuthCache() { | 65 HttpAuthCache::HttpAuthCache() { |
64 } | 66 } |
65 | 67 |
66 HttpAuthCache::~HttpAuthCache() { | 68 HttpAuthCache::~HttpAuthCache() { |
67 } | 69 } |
68 | 70 |
69 // Performance: O(n), where n is the number of realm entries. | 71 // Performance: O(n), where n is the number of realm entries. |
70 HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin, | 72 HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin, |
71 const std::string& realm, | 73 const std::string& realm, |
72 HttpAuth::Scheme scheme) { | 74 HttpAuth::Scheme scheme) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 // Copy all other paths. | 236 // Copy all other paths. |
235 for (Entry::PathList::const_reverse_iterator it2 = ++it->paths_.rbegin(); | 237 for (Entry::PathList::const_reverse_iterator it2 = ++it->paths_.rbegin(); |
236 it2 != it->paths_.rend(); ++it2) | 238 it2 != it->paths_.rend(); ++it2) |
237 entry->AddPath(*it2); | 239 entry->AddPath(*it2); |
238 // Copy nonce count (for digest authentication). | 240 // Copy nonce count (for digest authentication). |
239 entry->nonce_count_ = it->nonce_count_; | 241 entry->nonce_count_ = it->nonce_count_; |
240 } | 242 } |
241 } | 243 } |
242 | 244 |
243 } // namespace net | 245 } // namespace net |
OLD | NEW |