bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
RemoteResource.h
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the BES http package, part of the Hyrax data server.
4
5// Copyright (c) 2020 OPeNDAP, Inc.
6// Author: Nathan Potter <ndp@opendap.org>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23
24// Authors:
25// ndp Nathan Potter <ndp@opendap.org>
26
27#ifndef _bes_http_REMOTE_HTTP_RESOURCE_H_
28#define _bes_http_REMOTE_HTTP_RESOURCE_H_ 1
29
30#include <memory>
31#include <string>
32#include <vector>
33#include <mutex>
34
35#include "CurlUtils.h"
36
37namespace http {
38
39class url;
40
48private:
49 friend class RemoteResourceTest;
50
51 static std::string d_temp_file_dir;
52
54 static void set_temp_file_dir();
56 static std::mutex d_temp_file_dir_mutex;
57
59 std::shared_ptr<http::url> d_url;
60
62 int d_fd = 0;
63
65 bool d_initialized = false;
66
68 std::string d_uid;
69
71 std::string d_type;
72
74 std::string d_filename;
75
78 std::string d_basename;
79
81 bool d_delete_file = true;
82
84 std::vector<std::string> d_response_headers; // Response headers
85
87 void get_url(int fd);
88
90 static std::mutex d_mkstemp_mutex;
91
92 void set_filename_for_file_url();
93
94 void set_delete_temp_file();
95
96public:
98 RemoteResource() = default;
99 RemoteResource(const RemoteResource &rhs) = delete;
100 RemoteResource &operator=(const RemoteResource &rhs) = delete;
101 explicit RemoteResource(std::shared_ptr<http::url> target_url, std::string uid = "");
102
103 virtual ~RemoteResource();
104
105 void retrieve_resource();
106
111 std::string get_type() const { return d_type; }
112
114 std::string get_filename() const { return d_filename; }
115
117 int get_fd() const { return d_fd; }
118};
119
120} /* namespace http */
121
122#endif /* _bes_http_REMOTE_HTTP_RESOURCE_H_ */
std::string get_filename() const
Returns the file name in which the content of the URL has been stored.
int get_fd() const
Return the file descriptor to the open temp file.
RemoteResource()=default
The default constructor is here to ease testing. Remove if not needed. jhrg 3/8/23.
std::string get_type() const
Parse a URL into the protocol, host, path and query parts.
Definition url_impl.h:44
utility class for the HTTP catalog module
Definition TheBESKeys.h:51