libdap++  Updated for version 3.12.0
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 
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 
57 using std::string;
58 using std::vector;
59 
60 namespace libdap
61 {
62 
63 extern int www_trace;
64 extern int dods_keep_temps;
65 
79 {
80 private:
81  CURL *d_curl;
82  RCReader *d_rcr;
83  HTTPCache *d_http_cache;
84 
85  char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
86 
87  bool d_accept_deflate;
88 
89  string d_username; // extracted from URL
90  string d_password; // extracted from URL
91  string d_upstring; // used to pass info into curl
92 
93  string d_cookie_jar;
94 
95  vector<string> d_request_headers; // Request headers
96 
97  int d_dap_client_protocol_major;
98  int d_dap_client_protocol_minor;
99 
100  void www_lib_init();
101  long read_url(const string &url, FILE *stream, vector<string> *resp_hdrs,
102  const vector<string> *headers = 0);
103  // string get_temp_file(FILE *&stream) throw(InternalErr);
104  HTTPResponse *plain_fetch_url(const string &url);
105  HTTPResponse *caching_fetch_url(const string &url);
106 
107  bool url_uses_proxy_for(const string &url) throw();
108  bool url_uses_no_proxy_for(const string &url) throw();
109 
110  void extract_auth_info(string &url);
111 
112  friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb,
113  void *http_connect);
114  friend class HTTPConnectTest;
115  friend class ParseHeader;
116 
117 protected:
124  throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
125  }
127  throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
128  }
130  throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment");
131  }
133 
134 public:
135  HTTPConnect(RCReader *rcr);
136 
137  virtual ~HTTPConnect();
138 
139  void set_credentials(const string &u, const string &p);
140  void set_accept_deflate(bool defalte);
141  void set_xdap_protocol(int major, int minor);
142 
149  void set_cookie_jar(const string &cookie_jar)
150  {
151  d_cookie_jar = cookie_jar;
152  }
153 
159  void set_cache_enabled(bool enabled)
160  {
161  if (d_http_cache)
162  d_http_cache->set_cache_enabled(enabled);
163  }
164 
167  {
168  return (d_http_cache) ? d_http_cache->is_cache_enabled() : false;
169  }
170 
171  HTTPResponse *fetch_url(const string &url);
172 };
173 
174 } // namespace libdap
175 
176 #endif // _httpconnect_h
bool is_cache_enabled() const
Definition: HTTPCache.cc:626
void set_cache_enabled(bool mode)
Definition: HTTPCache.cc:614
void set_credentials(const string &u, const string &p)
Definition: HTTPConnect.cc:993
void set_cookie_jar(const string &cookie_jar)
Definition: HTTPConnect.h:149
void set_cache_enabled(bool enabled)
Definition: HTTPConnect.h:159
HTTPResponse * fetch_url(const string &url)
Definition: HTTPConnect.cc:569
A class for software fault reporting.
Definition: InternalErr.h:64
HTTPConnect(const HTTPConnect &)
Definition: HTTPConnect.h:126
friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb, void *http_connect)
friend class ParseHeader
Definition: HTTPConnect.h:115
void set_accept_deflate(bool defalte)
Definition: HTTPConnect.cc:919
void set_xdap_protocol(int major, int minor)
Definition: HTTPConnect.cc:956
virtual ~HTTPConnect()
Definition: HTTPConnect.cc:547
int dods_keep_temps
Definition: HTTPConnect.cc:77
friend class HTTPConnectTest
Definition: HTTPConnect.h:114
HTTPConnect & operator=(const HTTPConnect &)
Definition: HTTPConnect.h:129
int www_trace
Definition: HTTPConnect.cc:74