1 // Copyright 2014 The Chromium Authors 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 NET_HTTP_HTTP_AUTH_CHALLENGE_TOKENIZER_H_ 6 #define NET_HTTP_HTTP_AUTH_CHALLENGE_TOKENIZER_H_ 7 8 #include <string> 9 #include <string_view> 10 11 #include "net/base/net_export.h" 12 #include "net/http/http_util.h" 13 14 namespace net { 15 16 // Breaks up a challenge string into the the auth scheme and parameter list, 17 // according to RFC 2617 Sec 1.2: 18 // challenge = auth-scheme 1*SP 1#auth-param 19 // 20 // Depending on the challenge scheme, it may be appropriate to interpret the 21 // parameters as either a base-64 encoded string or a comma-delimited list 22 // of name-value pairs. param_pairs() and base64_param() methods are provided 23 // to support either usage. 24 class NET_EXPORT_PRIVATE HttpAuthChallengeTokenizer { 25 public: 26 explicit HttpAuthChallengeTokenizer(std::string_view challenge); 27 ~HttpAuthChallengeTokenizer(); 28 29 // Get the original text. challenge_text()30 std::string_view challenge_text() const { return challenge_; } 31 32 // Get the authenthication scheme of the challenge. The returned scheme is 33 // always lowercase. auth_scheme()34 const std::string& auth_scheme() const { return lower_case_scheme_; } 35 params()36 std::string_view params() const { return params_; } 37 HttpUtil::NameValuePairsIterator param_pairs() const; 38 std::string_view base64_param() const; 39 40 private: 41 void Init(std::string_view challenge); 42 43 std::string_view challenge_; 44 std::string_view params_; 45 46 std::string lower_case_scheme_; 47 }; 48 49 } // namespace net 50 51 #endif // NET_HTTP_HTTP_AUTH_CHALLENGE_TOKENIZER_H_ 52