Coverage Report

Created: 2026-03-12 17:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/fs/http_file_system.cpp
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
#include "io/fs/http_file_system.h"
19
20
#include <fstream>
21
22
#include "common/status.h"
23
#include "io/fs/err_utils.h"
24
#include "io/fs/file_system.h"
25
#include "io/fs/file_writer.h"
26
#include "io/fs/http_file_reader.h"
27
#include "service/http/http_status.h"
28
29
namespace doris::io {
30
HttpFileSystem::HttpFileSystem(Path&& root_path, std::string id,
31
                               std::map<std::string, std::string> properties)
32
0
        : RemoteFileSystem(std::move(root_path), std::move(id), FileSystemType::HTTP),
33
0
          _properties(std::move(properties)) {}
34
35
0
Status HttpFileSystem::_init(const std::string& url) {
36
0
    _url = url;
37
0
    return Status::OK();
38
0
}
39
40
Result<std::shared_ptr<HttpFileSystem>> HttpFileSystem::create(
41
        std::string id, const std::string& url,
42
0
        const std::map<std::string, std::string>& properties) {
43
0
    Path root_path = "";
44
0
    std::shared_ptr<HttpFileSystem> fs(
45
0
            new HttpFileSystem(std::move(root_path), std::move(id), properties));
46
47
0
    RETURN_IF_ERROR_RESULT(fs->_init(url));
48
49
0
    return fs;
50
0
}
51
52
Status HttpFileSystem::open_file_internal(const Path& path, FileReaderSPtr* reader,
53
0
                                          const FileReaderOptions& opts) {
54
0
    OpenFileInfo file_info;
55
0
    file_info.path = path;
56
    // Pass properties (including HTTP headers) to the file reader
57
0
    file_info.extend_info = _properties;
58
59
0
    auto http_reader = std::make_shared<HttpFileReader>(file_info, path.native(), opts.mtime);
60
0
    RETURN_IF_ERROR(http_reader->open(opts));
61
0
    *reader = http_reader;
62
0
    return Status::OK();
63
0
}
64
65
0
Status HttpFileSystem::file_size_impl(const Path& file, int64_t* file_size) const {
66
0
    FileReaderOptions opts;
67
0
    FileReaderSPtr reader;
68
0
    RETURN_IF_ERROR(const_cast<HttpFileSystem*>(this)->open_file(file, &reader, &opts));
69
0
    *file_size = reader->size();
70
0
    RETURN_IF_ERROR(reader->close());
71
0
    return Status::OK();
72
0
}
73
74
0
Status HttpFileSystem::exists_impl(const Path& path, bool* res) const {
75
0
    FileReaderSPtr reader;
76
0
    auto st = const_cast<HttpFileSystem*>(this)->open_file(path, &reader);
77
0
    if (st.ok()) {
78
0
        *res = true;
79
0
        return Status::OK();
80
0
    } else if (st.code() == HttpStatus::NOT_FOUND) {
81
0
        *res = false;
82
0
        return Status::OK();
83
0
    } else {
84
0
        return st;
85
0
    }
86
0
}
87
88
} // namespace doris::io