Coverage Report

Created: 2026-08-13 04:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
27
struct bufferevent_rate_limit_group;
28
29
namespace doris {
30
31
class ExecEnv;
32
class HttpRequest;
33
34
// A simple handler that serves incoming HTTP requests of file-download to send their respective HTTP responses.
35
//
36
// TODO(lingbin): implements two useful header ('If-Modified-Since' and 'RANGE') to reduce
37
// transmission consumption.
38
// We use parameter named 'file' to specify the static resource path, it is an absolute path.
39
class DownloadAction : public HttpHandlerWithAuth {
40
public:
41
    DownloadAction(ExecEnv* exec_env,
42
                   std::shared_ptr<bufferevent_rate_limit_group> rate_limit_group,
43
                   const std::vector<std::string>& allow_dirs);
44
45
    // for load error
46
    DownloadAction(ExecEnv* exec_env, const std::string& error_log_root_dir);
47
48
13
    virtual ~DownloadAction() {}
49
50
    void handle(HttpRequest* req) override;
51
52
private:
53
    enum DOWNLOAD_TYPE {
54
        NORMAL = 1,
55
        ERROR_LOG = 2,
56
    };
57
58
    Status check_token(HttpRequest* req);
59
    Status check_path_is_allowed(const std::string& path);
60
    Status check_log_path_is_allowed(const std::string& file_path);
61
62
    void handle_normal(HttpRequest* req, const std::string& file_param);
63
    void handle_error_log(HttpRequest* req, const std::string& file_param);
64
    void _handle(HttpRequest* req);
65
66
    DOWNLOAD_TYPE _download_type;
67
68
    std::vector<std::string> _allow_paths;
69
    std::string _error_log_root_dir;
70
    std::shared_ptr<bufferevent_rate_limit_group> _rate_limit_group;
71
}; // end class DownloadAction
72
73
} // end namespace doris