Update V8 to version 4.5.72.
[chromium-blink-merge.git] / net / http / http_auth_challenge_tokenizer.cc
blob75c2d673574bbb9d4743bf620cca5c740892f9d7
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.
5 #include "net/http/http_auth_challenge_tokenizer.h"
7 #include "base/strings/string_tokenizer.h"
9 namespace net {
11 HttpAuthChallengeTokenizer::HttpAuthChallengeTokenizer(
12 std::string::const_iterator begin,
13 std::string::const_iterator end)
14 : begin_(begin),
15 end_(end),
16 scheme_begin_(begin),
17 scheme_end_(begin),
18 params_begin_(end),
19 params_end_(end) {
20 Init(begin, end);
23 HttpAuthChallengeTokenizer::~HttpAuthChallengeTokenizer() {
26 HttpUtil::NameValuePairsIterator HttpAuthChallengeTokenizer::param_pairs()
27 const {
28 return HttpUtil::NameValuePairsIterator(params_begin_, params_end_, ',');
31 std::string HttpAuthChallengeTokenizer::base64_param() const {
32 // Strip off any padding.
33 // (See https://bugzilla.mozilla.org/show_bug.cgi?id=230351.)
35 // Our base64 decoder requires that the length be a multiple of 4.
36 int encoded_length = params_end_ - params_begin_;
37 while (encoded_length > 0 && encoded_length % 4 != 0 &&
38 params_begin_[encoded_length - 1] == '=') {
39 --encoded_length;
41 return std::string(params_begin_, params_begin_ + encoded_length);
44 void HttpAuthChallengeTokenizer::Init(std::string::const_iterator begin,
45 std::string::const_iterator end) {
46 // The first space-separated token is the auth-scheme.
47 // NOTE: we are more permissive than RFC 2617 which says auth-scheme
48 // is separated by 1*SP.
49 base::StringTokenizer tok(begin, end, HTTP_LWS);
50 if (!tok.GetNext()) {
51 // Default param and scheme iterators provide empty strings
52 return;
55 // Save the scheme's position.
56 scheme_begin_ = tok.token_begin();
57 scheme_end_ = tok.token_end();
59 params_begin_ = scheme_end_;
60 params_end_ = end;
61 HttpUtil::TrimLWS(&params_begin_, &params_end_);
64 } // namespace net