bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
CurlUtils.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_CURL_UTILS_H_
28#define _bes_http_CURL_UTILS_H_ 1
29
30#include <memory>
31#include <string>
32#include <vector>
33
34#include <curl/curl.h>
35#include <curl/easy.h>
36
37#include "BESRegex.h"
38#include "EffectiveUrl.h"
39
40namespace http {
42
43class EffectiveUrl;
44
45class url;
46}
47
48namespace curl {
49
52void http_get_and_write_resource(const std::shared_ptr<http::url> &target_url, int fd,
53 std::vector<std::string> *http_response_headers);
54
55void http_get(const std::string &target_url, std::vector<char> &buf);
56
57bool http_head(const std::string &target_url, int tries = 3, unsigned long wait_time_us = 1'000'000);
58void http_get(const std::string &target_url, std::string &buf);
59
60void super_easy_perform(CURL *ceh);
62
63std::shared_ptr<http::EffectiveUrl> get_redirect_url(const std::shared_ptr<http::url> &url);
64
65std::string filter_aws_url(const std::string &eff_url);
66
67CURL *init(const std::string &target_url, const curl_slist *http_request_headers,
68 std::vector<std::string> *resp_hdrs);
69
70void set_error_buffer(CURL *ceh, char *error_buffer);
71
72std::string get_netrc_filename();
73
74std::string get_cookie_filename();
75
76bool is_retryable(const std::string &url);
77
78unsigned long max_redirects();
79
80std::string hyrax_user_agent();
81
82void eval_curl_easy_setopt_result(CURLcode result, const std::string &msg_base, const std::string &opt_name,
83 const char *ebuf, const std::string &file, unsigned int line);
84
85std::string get_range_arg_string(const unsigned long long &offset, const unsigned long long &size);
86
87std::string error_message(CURLcode response_code, const char *error_buf);
88
89void read_data(CURL *c_handle);
90
91curl_slist *append_http_header(curl_slist *slist, const std::string &header_name, const std::string &value);
92
93curl_slist *add_edl_auth_headers(curl_slist *request_headers);
94
95curl_slist *sign_s3_url(const std::string &target_url, http::AccessCredentials *ac, curl_slist *req_headers);
96
97// TODO Remove when no longer needed. jhrg 2/20/25
98curl_slist *sign_s3_url(const std::shared_ptr<http::url> &target_url, http::AccessCredentials *ac,
99 curl_slist *req_headers);
100
101bool is_url_signed_for_s3(const std::string &url);
102bool is_url_signed_for_s3(const std::shared_ptr<http::url> &target_url);
103
104} // namespace curl
105
106#endif /* _bes_http_CURL_UTILS_H_ */
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