bes  Updated for version 3.20.8
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 <string>
31 #include <vector>
32 
33 #include <curl/curl.h>
34 #include <curl/easy.h>
35 
36 #include "rapidjson/document.h"
37 #include "BESRegex.h"
38 #include "EffectiveUrl.h"
39 
40 namespace curl {
41 
42 void http_get_and_write_resource(const std::string &url,
43  const int fd,
44  std::vector<std::string> *http_response_headers);
45 
46 void http_get(const std::string &url, char *response_buf);
47 
48 std::string http_get_as_string(const std::string &url);
49 
50 rapidjson::Document http_get_as_json(const std::string &target_url);
51 
52 http::EffectiveUrl *retrieve_effective_url(const std::string &target_url);
53 
54 std::string get_netrc_filename();
55 
56 std::string get_cookie_filename();
57 
58 bool is_retryable(std::string url);
59 
60 unsigned long max_redirects();
61 
62 std::string hyrax_user_agent();
63 
64 CURL *init(const std::string &target_url,
65  const struct curl_slist *http_request_headers,
66  std::vector<std::string> *resp_hdrs);
67 
68 CURL *init(CURL *ceh,
69  const std::string &target_url,
70  const struct curl_slist *http_request_headers,
71  std::vector<std::string> *http_response_hdrs);
72 
73 bool configure_curl_handle_for_proxy(CURL *ceh, const std::string &url);
74 
75 void set_error_buffer(CURL *ceh, char *error_buffer);
76 
77 void unset_error_buffer(CURL *ceh);
78 
79 void eval_curl_easy_setopt_result(CURLcode result,
80  std::string msg_base,
81  std::string opt_name,
82  char *ebuf, std::string file,
83  unsigned int line);
84 
85 bool eval_curl_easy_perform_code(CURL *ceh,
86  std::string url,
87  CURLcode curl_code,
88  char *error_buffer,
89  unsigned int attempt);
90 
91 bool eval_http_get_response(CURL *ceh, char *error_buffer, const std::string &requested_url);
92 
93 void super_easy_perform(CURL *ceh);
94 
95 std::string get_effective_url(CURL *ceh, std::string requested_url);
96 
97 std::string get_range_arg_string(const unsigned long long &offset, const unsigned long long &size);
98 
99 std::string http_status_to_string(int status);
100 
101 std::string error_message(CURLcode response_code, char *error_buf);
102 
103 size_t c_write_data(void *buffer, size_t size, size_t nmemb, void *data);
104 
105 void read_data(CURL *c_handle);
106 
107 curl_slist *append_http_header(curl_slist *slist, const std::string &header_name, const std::string &value);
108 
109 curl_slist *add_auth_headers(curl_slist *request_headers);
110 
111 
112 } // namespace curl
113 
114 #endif /* _bes_http_CURL_UTILS_H_ */
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2585