1// Copyright 2015 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef WEBSERVER_LIBWEBSERV_REQUEST_HANDLER_CALLBACK_H_
16#define WEBSERVER_LIBWEBSERV_REQUEST_HANDLER_CALLBACK_H_
17
18#include <base/callback.h>
19#include <base/macros.h>
20#include <libwebserv/export.h>
21#include <libwebserv/request_handler_interface.h>
22
23namespace libwebserv {
24
25// A simple request handler that wraps a callback function.
26// Essentially, it redirects the RequestHandlerInterface::HandleRequest calls
27// to the provided callback.
28class LIBWEBSERV_EXPORT RequestHandlerCallback final
29    : public RequestHandlerInterface {
30 public:
31  explicit RequestHandlerCallback(
32      const base::Callback<HandlerSignature>& callback);
33
34  void HandleRequest(std::unique_ptr<Request> request,
35                     std::unique_ptr<Response> response) override;
36
37 private:
38  base::Callback<HandlerSignature> callback_;
39  DISALLOW_COPY_AND_ASSIGN(RequestHandlerCallback);
40};
41
42}  // namespace libwebserv
43
44#endif  // WEBSERVER_LIBWEBSERV_REQUEST_HANDLER_CALLBACK_H_
45