• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_UTILS_H_
16 #define WEBSERVER_LIBWEBSERV_REQUEST_UTILS_H_
17 
18 #include <memory>
19 #include <vector>
20 
21 #include <base/callback_forward.h>
22 #include <brillo/errors/error.h>
23 #include <libwebserv/export.h>
24 
25 namespace libwebserv {
26 
27 class Request;
28 class Response;
29 
30 using GetRequestDataSuccessCallback =
31     base::Callback<void(std::unique_ptr<Request> request,
32                         std::unique_ptr<Response> response,
33                         std::vector<uint8_t> data)>;
34 
35 using GetRequestDataErrorCallback =
36     base::Callback<void(std::unique_ptr<Request> request,
37                         std::unique_ptr<Response> response,
38                         const brillo::Error* error)>;
39 
40 // Reads the request data from |request| asynchronously and returns the data
41 // by calling |success_callback|. If an error occurred, |error_callback| is
42 // invoked with the error information passed into |error| parameter.
43 // The function takes ownership of the request and response objects for the
44 // duration of operation and returns them back via the callbacks.
45 LIBWEBSERV_EXPORT void GetRequestData(
46     std::unique_ptr<Request> request,
47     std::unique_ptr<Response> response,
48     const GetRequestDataSuccessCallback& success_callback,
49     const GetRequestDataErrorCallback& error_callback);
50 
51 }  // namespace libwebserv
52 
53 #endif  // WEBSERVER_LIBWEBSERV_REQUEST_UTILS_H_
54