libdap++  Updated for version 3.8.2
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 #include <curl/easy.h>
34 
35 #ifndef _rc_reader_h_
36 #include "RCReader.h"
37 #endif
38 
39 #ifndef _object_type_h
40 #include "ObjectType.h"
41 #endif
42 
43 #ifndef _http_cache_h
44 #include "HTTPCache.h"
45 #endif
46 
47 #ifndef http_response_h
48 #include "HTTPResponse.h"
49 #endif
50 
51 #ifndef _util_h
52 #include "util.h"
53 #endif
54 
55 using std::string;
56 using std::vector;
57 
58 namespace libdap
59 {
60 
61 extern int www_trace;
62 extern int dods_keep_temps;
63 
77 {
78 private:
79  CURL *d_curl;
80  RCReader *d_rcr;
81  HTTPCache *d_http_cache;
82 
83  char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
84 
85  bool d_accept_deflate;
86 
87  string d_username; // extracted from URL
88  string d_password; // extracted from URL
89  string d_upstring; // used to pass info into curl
90 
91  string d_cookie_jar;
92 
93  vector<string> d_request_headers; // Request headers
94 
95  int d_dap_client_protocol_major;
96  int d_dap_client_protocol_minor;
97 
98  void www_lib_init();
99  long read_url(const string &url, FILE *stream, vector<string> *resp_hdrs,
100  const vector<string> *headers = 0);
101  // string get_temp_file(FILE *&stream) throw(InternalErr);
102  HTTPResponse *plain_fetch_url(const string &url);
103  HTTPResponse *caching_fetch_url(const string &url);
104 
105  bool url_uses_proxy_for(const string &url) throw();
106  bool url_uses_no_proxy_for(const string &url) throw();
107 
108  void extract_auth_info(string &url);
109 
110  friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb,
111  void *http_connect);
112  friend class HTTPConnectTest;
113  friend class ParseHeader;
114 
115 protected:
122  throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
123  }
125  throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
126  }
128  throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment");
129  }
131 
132 public:
133  HTTPConnect(RCReader *rcr);
134 
135  virtual ~HTTPConnect();
136 
137  void set_credentials(const string &u, const string &p);
138  void set_accept_deflate(bool defalte);
139  void set_xdap_protocol(int major, int minor);
140 
147  void set_cookie_jar(const string &cookie_jar)
148  {
149  d_cookie_jar = cookie_jar;
150  }
151 
157  void set_cache_enabled(bool enabled)
158  {
159  if (d_http_cache)
160  d_http_cache->set_cache_enabled(enabled);
161  }
162 
165  {
166  return (d_http_cache) ? d_http_cache->is_cache_enabled() : false;
167  }
168 
169  HTTPResponse *fetch_url(const string &url);
170 };
171 
172 } // namespace libdap
173 
174 #endif // _httpconnect_h