libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
HTTPConnect.h
Go to the documentation of this file.
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26#ifndef _httpconnect_h
27#define _httpconnect_h
28
29#include <mutex>
30#include <string>
31#include <vector>
32
33#include <curl/curl.h>
34
35#include "HTTPCache.h"
36
37namespace libdap {
38
39class RCReader;
40class HTTPCache;
41class HTTPResponse;
42
43extern int www_trace;
44extern int www_trace_extensive;
45
52private:
53 CURL *d_curl = nullptr;
54 RCReader *d_rcr = nullptr;
55 HTTPCache *d_http_cache = nullptr;
56
57 char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
58 std::string d_content_type; // apparently read by libcurl; this is valid only after curl_easy_perform()
59
60 bool d_accept_deflate = false; // Use deflate encoding for HTTP requests
61
62 std::string d_username; // extracted from URL
63 std::string d_password; // extracted from URL
64 std::string d_upstring; // used to pass info into curl
65
66 std::string d_cookie_jar;
67
68 std::vector<std::string> d_request_headers; // Request headers
69
70 int d_dap_client_protocol_major = 2;
71 int d_dap_client_protocol_minor = 0;
72
73 bool d_use_cpp_streams; // Build HTTPResponse objects using fstream and not FILE*
74
75 bool d_verbose_runtime = false;
76 bool d_cached_response = false;
77
78 std::mutex d_connect_mutex; // Used to lock the public interface.
79
80 void www_lib_init();
81
82 long read_url(const std::string &url, FILE *stream, std::vector<std::string> &resp_hdrs,
83 const std::vector<std::string> &headers);
84
85 long read_url(const std::string &url, FILE *stream, std::vector<std::string> &resp_hdrs);
86
87 HTTPResponse *plain_fetch_url(const std::string &url);
88
89 HTTPResponse *caching_fetch_url(const std::string &url);
90
91 bool url_uses_proxy_for(const std::string &url);
92
93 bool url_uses_no_proxy_for(const std::string &url) noexcept;
94
95 void set_verbose_runtime(bool verbose) { d_verbose_runtime = verbose; }
96
97 bool is_cached_response() const { return d_cached_response; }
98
99 friend class HTTPConnectTest;
100
102
103 friend class ParseHeader;
104
105public:
106 explicit HTTPConnect(RCReader *rcr, bool use_cpp = false);
107
113 HTTPConnect() = delete;
114
115 HTTPConnect(const HTTPConnect &) = delete;
116
119
120 virtual ~HTTPConnect();
121
122 void set_credentials(const std::string &u, const std::string &p);
123
124 void set_accept_deflate(bool deflate);
125
126 void set_xdap_protocol(int major, int minor);
127
128 bool use_cpp_streams() const { return d_use_cpp_streams; }
129
131 std::lock_guard<std::mutex> lock(d_connect_mutex);
132 d_use_cpp_streams = use_cpp_streams;
133 }
134
141 void set_cookie_jar(const std::string &cookie_jar) {
142 std::lock_guard<std::mutex> lock(d_connect_mutex);
143 d_cookie_jar = cookie_jar;
144 }
145
151 void set_cache_enabled(bool enabled) {
152 std::lock_guard<std::mutex> lock(d_connect_mutex);
153 if (d_http_cache)
154 d_http_cache->set_cache_enabled(enabled);
155 }
156
158 bool is_cache_enabled() const { return (d_http_cache) != nullptr && d_http_cache->is_cache_enabled(); }
159
160 HTTPResponse *fetch_url(const std::string &url);
161};
162
163} // namespace libdap
164
165#endif // _httpconnect_h
HTTPConnect(RCReader *rcr, bool use_cpp=false)
bool use_cpp_streams() const
void set_cookie_jar(const std::string &cookie_jar)
bool is_cache_enabled() const
HTTPConnect(const HTTPConnect &)=delete
friend class ParseHeader
void set_accept_deflate(bool deflate)
void set_use_cpp_streams(bool use_cpp_streams)
friend class HTTPThreadsConnectTest
friend class HTTPConnectTest
Definition HTTPConnect.h:99
void set_cache_enabled(bool enabled)
HTTPConnect & operator=(const HTTPConnect &)=delete
void set_xdap_protocol(int major, int minor)
void set_credentials(const std::string &u, const std::string &p)
HTTPResponse * fetch_url(const std::string &url)
top level DAP object to house generic methods
Definition AISConnect.cc:30
int www_trace
int www_trace_extensive