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