be/src/service/http/action/download_action.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <string> |
21 | | #include <vector> |
22 | | |
23 | | #include "common/status.h" |
24 | | #include "service/http/http_handler.h" |
25 | | #include "service/http/http_handler_with_auth.h" |
26 | | #include "util/threadpool.h" |
27 | | |
28 | | struct bufferevent_rate_limit_group; |
29 | | |
30 | | namespace doris { |
31 | | |
32 | | class ExecEnv; |
33 | | class HttpRequest; |
34 | | |
35 | | // A simple handler that serves incoming HTTP requests of file-download to send their respective HTTP responses. |
36 | | // |
37 | | // TODO(lingbin): implements two useful header ('If-Modified-Since' and 'RANGE') to reduce |
38 | | // transmission consumption. |
39 | | // We use parameter named 'file' to specify the static resource path, it is an absolute path. |
40 | | class DownloadAction : public HttpHandlerWithAuth { |
41 | | public: |
42 | | DownloadAction(ExecEnv* exec_env, |
43 | | std::shared_ptr<bufferevent_rate_limit_group> rate_limit_group, |
44 | | const std::vector<std::string>& allow_dirs, int32_t num_workers = 0); |
45 | | |
46 | | // for load error |
47 | | DownloadAction(ExecEnv* exec_env, const std::string& error_log_root_dir); |
48 | | |
49 | 17 | virtual ~DownloadAction() {} |
50 | | |
51 | | void handle(HttpRequest* req) override; |
52 | | |
53 | | private: |
54 | | enum DOWNLOAD_TYPE { |
55 | | NORMAL = 1, |
56 | | ERROR_LOG = 2, |
57 | | }; |
58 | | |
59 | | Status check_token(HttpRequest* req); |
60 | | Status check_path_is_allowed(const std::string& path); |
61 | | Status check_log_path_is_allowed(const std::string& file_path); |
62 | | |
63 | | void handle_normal(HttpRequest* req, const std::string& file_param); |
64 | | void handle_error_log(HttpRequest* req, const std::string& file_param); |
65 | | void _handle(HttpRequest* req); |
66 | | |
67 | | DOWNLOAD_TYPE _download_type; |
68 | | |
69 | | std::vector<std::string> _allow_paths; |
70 | | std::string _error_log_root_dir; |
71 | | int32_t _num_workers; |
72 | | std::unique_ptr<ThreadPool> _download_workers; |
73 | | |
74 | | std::shared_ptr<bufferevent_rate_limit_group> _rate_limit_group; |
75 | | }; // end class DownloadAction |
76 | | |
77 | | } // end namespace doris |