[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 1 | // Copyright 2014 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 | |
bnc | 3698b0a0 | 2016-12-09 23:36:50 | [diff] [blame] | 5 | #ifndef NET_HTTP_HTTP_AUTH_CHALLENGE_TOKENIZER_H_ |
| 6 | #define NET_HTTP_HTTP_AUTH_CHALLENGE_TOKENIZER_H_ |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "net/base/net_export.h" |
| 11 | #include "net/http/http_util.h" |
| 12 | |
| 13 | namespace net { |
| 14 | |
| 15 | // Breaks up a challenge string into the the auth scheme and parameter list, |
| 16 | // according to RFC 2617 Sec 1.2: |
| 17 | // challenge = auth-scheme 1*SP 1#auth-param |
| 18 | // |
| 19 | // Depending on the challenge scheme, it may be appropriate to interpret the |
| 20 | // parameters as either a base-64 encoded string or a comma-delimited list |
| 21 | // of name-value pairs. param_pairs() and base64_param() methods are provided |
| 22 | // to support either usage. |
| 23 | class NET_EXPORT_PRIVATE HttpAuthChallengeTokenizer { |
| 24 | public: |
| 25 | HttpAuthChallengeTokenizer(std::string::const_iterator begin, |
| 26 | std::string::const_iterator end); |
thakis | ba38d5369 | 2015-05-12 17:54:01 | [diff] [blame] | 27 | ~HttpAuthChallengeTokenizer(); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 28 | |
| 29 | // Get the original text. |
| 30 | std::string challenge_text() const { |
| 31 | return std::string(begin_, end_); |
| 32 | } |
| 33 | |
| 34 | // Get the auth scheme of the challenge. |
| 35 | std::string::const_iterator scheme_begin() const { return scheme_begin_; } |
| 36 | std::string::const_iterator scheme_end() const { return scheme_end_; } |
| 37 | std::string scheme() const { |
| 38 | return std::string(scheme_begin_, scheme_end_); |
| 39 | } |
| 40 | |
[email protected] | b4a91607 | 2014-03-18 15:44:05 | [diff] [blame] | 41 | std::string::const_iterator params_begin() const { return params_begin_; } |
| 42 | std::string::const_iterator params_end() const { return params_end_; } |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 43 | HttpUtil::NameValuePairsIterator param_pairs() const; |
| 44 | std::string base64_param() const; |
| 45 | |
| 46 | private: |
| 47 | void Init(std::string::const_iterator begin, |
| 48 | std::string::const_iterator end); |
| 49 | |
| 50 | std::string::const_iterator begin_; |
| 51 | std::string::const_iterator end_; |
| 52 | |
| 53 | std::string::const_iterator scheme_begin_; |
| 54 | std::string::const_iterator scheme_end_; |
| 55 | |
| 56 | std::string::const_iterator params_begin_; |
| 57 | std::string::const_iterator params_end_; |
| 58 | }; |
| 59 | |
| 60 | } // namespace net |
| 61 | |
bnc | 3698b0a0 | 2016-12-09 23:36:50 | [diff] [blame] | 62 | #endif // NET_HTTP_HTTP_AUTH_CHALLENGE_TOKENIZER_H_ |