libdap Updated for version 3.18.1
HTTPConnect.h
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
30#include <string>
31
32#include <curl/curl.h>
33//No longer used in CURL - pwest April 09, 2012
34//#include <curl/types.h>
35#include <curl/easy.h>
36
37#ifndef _rc_reader_h_
38#include "RCReader.h"
39#endif
40
41#ifndef _object_type_h
42#include "ObjectType.h"
43#endif
44
45#ifndef _http_cache_h
46#include "HTTPCache.h"
47#endif
48
49#ifndef http_response_h
50#include "HTTPResponse.h"
51#endif
52
53#ifndef _util_h
54#include "util.h"
55#endif
56
57using std::string;
58using std::vector;
59
60namespace libdap
61{
62
63extern int www_trace;
64extern int dods_keep_temps;
65
73{
74private:
75 CURL *d_curl;
76 RCReader *d_rcr;
77 HTTPCache *d_http_cache;
78
79 char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
80 std::string d_content_type; // apparently read by libcurl; this is valid only after curl_easy_perform()
81
82 bool d_accept_deflate;
83
84 string d_username; // extracted from URL
85 string d_password; // extracted from URL
86 string d_upstring; // used to pass info into curl
87
88 string d_cookie_jar;
89
90 vector<string> d_request_headers; // Request headers
91
92 int d_dap_client_protocol_major;
93 int d_dap_client_protocol_minor;
94
95 bool d_use_cpp_streams; // Build HTTPResponse objects using fstream and not FILE*
96
97 void www_lib_init();
98 long read_url(const string &url, FILE *stream, vector<string> *resp_hdrs,
99 const vector<string> *headers = 0);
100
101 HTTPResponse *plain_fetch_url(const string &url);
102 HTTPResponse *caching_fetch_url(const string &url);
103
104 bool url_uses_proxy_for(const string &url);
105 bool url_uses_no_proxy_for(const string &url) throw();
106
107 void extract_auth_info(string &url);
108
109 friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb,
110 void *http_connect);
111 friend class HTTPConnectTest;
112 friend class ParseHeader;
113
114protected:
120 HTTPConnect();
121 HTTPConnect(const HTTPConnect &);
122 HTTPConnect &operator=(const HTTPConnect &);
124
125public:
126 HTTPConnect(RCReader *rcr, bool use_cpp = false);
127
128 virtual ~HTTPConnect();
129
130 void set_credentials(const string &u, const string &p);
131 void set_accept_deflate(bool defalte);
132 void set_xdap_protocol(int major, int minor);
133
134 bool use_cpp_streams() const { return d_use_cpp_streams; }
135 void set_use_cpp_streams(bool use_cpp_streams) { d_use_cpp_streams = use_cpp_streams; }
136
143 void set_cookie_jar(const string &cookie_jar) { d_cookie_jar = cookie_jar; }
144
150 void set_cache_enabled(bool enabled) {
151 if (d_http_cache)
152 d_http_cache->set_cache_enabled(enabled);
153 }
154
156 bool is_cache_enabled() { return (d_http_cache) ? d_http_cache->is_cache_enabled() : false; }
157
158 HTTPResponse *fetch_url(const string &url);
159};
160
161} // namespace libdap
162
163#endif // _httpconnect_h
void set_cache_enabled(bool mode)
Definition: HTTPCache.cc:635
bool is_cache_enabled() const
Definition: HTTPCache.cc:647
void set_accept_deflate(bool defalte)
Definition: HTTPConnect.cc:998
HTTPResponse * fetch_url(const string &url)
Definition: HTTPConnect.cc:617
void set_credentials(const string &u, const string &p)
void set_cache_enabled(bool enabled)
Definition: HTTPConnect.h:150
void set_xdap_protocol(int major, int minor)
void set_cookie_jar(const string &cookie_jar)
Definition: HTTPConnect.h:143