Leo Lai | 16dea87 | 2019-12-06 10:39:21 +0800 | [diff] [blame] | 1 | // Copyright 2015 The Chromium OS 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. |
Alex Vakulenko | fdb42ae | 2015-09-25 11:23:00 -0700 | [diff] [blame] | 4 | |
| 5 | #ifndef WEBSERVER_LIBWEBSERV_REQUEST_UTILS_H_ |
| 6 | #define WEBSERVER_LIBWEBSERV_REQUEST_UTILS_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/callback_forward.h> |
Alex Vakulenko | 9e1596d | 2015-10-13 10:01:34 -0700 | [diff] [blame] | 12 | #include <brillo/errors/error.h> |
Alex Vakulenko | fdb42ae | 2015-09-25 11:23:00 -0700 | [diff] [blame] | 13 | #include <libwebserv/export.h> |
| 14 | |
| 15 | namespace libwebserv { |
| 16 | |
| 17 | class Request; |
| 18 | class Response; |
| 19 | |
| 20 | using GetRequestDataSuccessCallback = |
| 21 | base::Callback<void(std::unique_ptr<Request> request, |
| 22 | std::unique_ptr<Response> response, |
| 23 | std::vector<uint8_t> data)>; |
| 24 | |
| 25 | using GetRequestDataErrorCallback = |
| 26 | base::Callback<void(std::unique_ptr<Request> request, |
| 27 | std::unique_ptr<Response> response, |
Alex Vakulenko | 9e1596d | 2015-10-13 10:01:34 -0700 | [diff] [blame] | 28 | const brillo::Error* error)>; |
Alex Vakulenko | fdb42ae | 2015-09-25 11:23:00 -0700 | [diff] [blame] | 29 | |
| 30 | // Reads the request data from |request| asynchronously and returns the data |
| 31 | // by calling |success_callback|. If an error occurred, |error_callback| is |
| 32 | // invoked with the error information passed into |error| parameter. |
| 33 | // The function takes ownership of the request and response objects for the |
| 34 | // duration of operation and returns them back via the callbacks. |
| 35 | LIBWEBSERV_EXPORT void GetRequestData( |
| 36 | std::unique_ptr<Request> request, |
| 37 | std::unique_ptr<Response> response, |
| 38 | const GetRequestDataSuccessCallback& success_callback, |
| 39 | const GetRequestDataErrorCallback& error_callback); |
| 40 | |
| 41 | } // namespace libwebserv |
| 42 | |
| 43 | #endif // WEBSERVER_LIBWEBSERV_REQUEST_UTILS_H_ |