Coverage Report

Created: 2026-03-15 08:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/batch_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 batching file-download to send their
36
// respective HTTP responses.
37
//
38
// We use parameter named 'dir' to specify the static resource path, it is an absolute path.
39
//
40
// In HEAD request, then this handler will return the list of files in the specified directory.
41
//
42
// In GET request, the file names to download are specified in the request body as a list of strings,
43
// separated by '\n'. To avoid cost resource, the maximum number of files to download in a batch is 64.
44
class BatchDownloadAction : public HttpHandlerWithAuth {
45
public:
46
    BatchDownloadAction(ExecEnv* exec_env,
47
                        std::shared_ptr<bufferevent_rate_limit_group> rate_limit_group,
48
                        const std::vector<std::string>& allow_dirs);
49
50
0
    ~BatchDownloadAction() override = default;
51
52
    void handle(HttpRequest* req) override;
53
54
private:
55
    Status _check_token(HttpRequest* req);
56
    Status _check_path_is_allowed(const std::string& path);
57
58
    void _handle(HttpRequest* req, const std::string& dir_path);
59
    void _handle_batch_download(HttpRequest* req, const std::string& dir_path);
60
61
    std::vector<std::string> _allow_paths;
62
    std::shared_ptr<bufferevent_rate_limit_group> _rate_limit_group;
63
};
64
65
} // end namespace doris