1// Copyright (c) 2010 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
5#ifndef NET_HTTP_HTTP_AUTH_HANDLER_BASIC_H_
6#define NET_HTTP_HTTP_AUTH_HANDLER_BASIC_H_
7#pragma once
8
9#include <string>
10
11#include "base/string16.h"
12#include "net/http/http_auth_handler.h"
13#include "net/http/http_auth_handler_factory.h"
14
15namespace net {
16
17// Code for handling http basic authentication.
18class HttpAuthHandlerBasic : public HttpAuthHandler {
19 public:
20  class Factory : public HttpAuthHandlerFactory {
21   public:
22    Factory();
23    virtual ~Factory();
24
25    virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge,
26                                  HttpAuth::Target target,
27                                  const GURL& origin,
28                                  CreateReason reason,
29                                  int digest_nonce_count,
30                                  const BoundNetLog& net_log,
31                                  scoped_ptr<HttpAuthHandler>* handler);
32  };
33
34  virtual HttpAuth::AuthorizationResult HandleAnotherChallenge(
35      HttpAuth::ChallengeTokenizer* challenge);
36
37 protected:
38  virtual bool Init(HttpAuth::ChallengeTokenizer* challenge);
39
40  virtual int GenerateAuthTokenImpl(const string16* username,
41                                    const string16* password,
42                                    const HttpRequestInfo* request,
43                                    CompletionCallback* callback,
44                                    std::string* auth_token);
45
46 private:
47  ~HttpAuthHandlerBasic() {}
48
49  bool ParseChallenge(HttpAuth::ChallengeTokenizer* challenge);
50};
51
52}  // namespace net
53
54#endif  // NET_HTTP_HTTP_AUTH_HANDLER_BASIC_H_
55