Commit 7306d30e authored by Asanka Herath's avatar Asanka Herath Committed by Commit Bot

[net/auth] Use StringPiece instead of constructing lots of strings.

R=mmenke@chromium.org

Bug: 927182
Change-Id: I610973df09e2fe1e370a4ca2b2c3ecc90af790c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1907150
Commit-Queue: Asanka Herath <asanka@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714338}
parent 303b2305
......@@ -7,6 +7,7 @@
#include <string>
#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
#include "net/http/http_util.h"
......@@ -32,10 +33,8 @@ class NET_EXPORT_PRIVATE HttpAuthChallengeTokenizer {
}
// Get the auth scheme of the challenge.
std::string::const_iterator scheme_begin() const { return scheme_begin_; }
std::string::const_iterator scheme_end() const { return scheme_end_; }
std::string scheme() const {
return std::string(scheme_begin_, scheme_end_);
base::StringPiece scheme() const {
return base::StringPiece(scheme_begin_, scheme_end_);
}
std::string::const_iterator params_begin() const { return params_begin_; }
......
......@@ -46,7 +46,7 @@ class NET_EXPORT_PRIVATE HttpAuthHandlerBasic : public HttpAuthHandler {
HttpAuthChallengeTokenizer* challenge) override;
private:
~HttpAuthHandlerBasic() override {}
~HttpAuthHandlerBasic() override = default;
bool ParseChallenge(HttpAuthChallengeTokenizer* challenge);
};
......
......@@ -200,7 +200,7 @@ int HttpAuthHandlerRegistryFactory::CreateAuthHandler(
const NetLogWithSource& net_log,
HostResolver* host_resolver,
std::unique_ptr<HttpAuthHandler>* handler) {
std::string scheme = challenge->scheme();
auto scheme = challenge->scheme();
if (scheme.empty()) {
handler->reset();
return ERR_INVALID_RESPONSE;
......
......@@ -2,17 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/http/http_auth_multi_round_parse.h"
#include "base/base64.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "net/http/http_auth_challenge_tokenizer.h"
#include "net/http/http_auth_multi_round_parse.h"
namespace net {
namespace {
// Check that the scheme in the challenge matches the expected scheme
bool SchemeIsValid(const std::string& scheme,
bool SchemeIsValid(base::StringPiece scheme,
HttpAuthChallengeTokenizer* challenge) {
// There is no guarantee that challenge->scheme() is valid ASCII, but
// LowerCaseEqualsASCII will do the right thing even if it isn't.
......@@ -23,7 +25,7 @@ bool SchemeIsValid(const std::string& scheme,
} // namespace
HttpAuth::AuthorizationResult ParseFirstRoundChallenge(
const std::string& scheme,
base::StringPiece scheme,
HttpAuthChallengeTokenizer* challenge) {
// Verify the challenge's auth-scheme.
if (!SchemeIsValid(scheme, challenge))
......@@ -37,7 +39,7 @@ HttpAuth::AuthorizationResult ParseFirstRoundChallenge(
}
HttpAuth::AuthorizationResult ParseLaterRoundChallenge(
const std::string& scheme,
base::StringPiece scheme,
HttpAuthChallengeTokenizer* challenge,
std::string* encoded_token,
std::string* decoded_token) {
......
......@@ -7,6 +7,7 @@
#include <string>
#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
#include "net/http/http_auth.h"
......@@ -15,11 +16,11 @@ namespace net {
class HttpAuthChallengeTokenizer;
NET_EXPORT_PRIVATE HttpAuth::AuthorizationResult ParseFirstRoundChallenge(
const std::string& scheme,
base::StringPiece scheme,
HttpAuthChallengeTokenizer* challenge);
NET_EXPORT_PRIVATE HttpAuth::AuthorizationResult ParseLaterRoundChallenge(
const std::string& scheme,
base::StringPiece scheme,
HttpAuthChallengeTokenizer* challenge,
std::string* encoded_token,
std::string* decoded_token);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment