00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _httpconnect_h
00027 #define _httpconnect_h
00028
00029
00030 #include <string>
00031
00032 #include <curl/curl.h>
00033 #include <curl/types.h>
00034 #include <curl/easy.h>
00035
00036 #ifndef _rc_reader_h_
00037 #include "RCReader.h"
00038 #endif
00039
00040 #ifndef _object_type_h
00041 #include "ObjectType.h"
00042 #endif
00043
00044 #ifndef _http_cache_h
00045 #include "HTTPCache.h"
00046 #endif
00047
00048 #ifndef http_response_h
00049 #include "HTTPResponse.h"
00050 #endif
00051
00052 #ifndef _util_h
00053 #include "util.h"
00054 #endif
00055
00056 using std::string;
00057 using std::vector;
00058
00059 namespace libdap
00060 {
00061
00062 extern int www_trace;
00063 extern int dods_keep_temps;
00064
00077 class HTTPConnect
00078 {
00079 private:
00080 CURL *d_curl;
00081 RCReader *d_rcr;
00082 HTTPCache *d_http_cache;
00083
00084 char d_error_buffer[CURL_ERROR_SIZE];
00085
00086 bool d_accept_deflate;
00087
00088 string d_username;
00089 string d_password;
00090 string d_upstring;
00091
00092 string d_cookie_jar;
00093
00094 vector<string> d_request_headers;
00095
00096 int d_dap_client_protocol_major;
00097 int d_dap_client_protocol_minor;
00098
00099 void www_lib_init();
00100 long read_url(const string &url, FILE *stream, vector<string> *resp_hdrs,
00101 const vector<string> *headers = 0);
00102
00103 HTTPResponse *plain_fetch_url(const string &url);
00104 HTTPResponse *caching_fetch_url(const string &url);
00105
00106 bool url_uses_proxy_for(const string &url) throw();
00107 bool url_uses_no_proxy_for(const string &url) throw();
00108
00109 void extract_auth_info(string &url);
00110
00111 friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb,
00112 void *http_connect);
00113 friend class HTTPConnectTest;
00114 friend class ParseHeader;
00115
00116 protected:
00122 HTTPConnect() {
00123 throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
00124 }
00125 HTTPConnect(const HTTPConnect &) {
00126 throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
00127 }
00128 HTTPConnect &operator=(const HTTPConnect &) {
00129 throw InternalErr(__FILE__, __LINE__, "Unimplemented assignment");
00130 }
00132
00133 public:
00134 HTTPConnect(RCReader *rcr);
00135
00136 virtual ~HTTPConnect();
00137
00138 void set_credentials(const string &u, const string &p);
00139 void set_accept_deflate(bool defalte);
00140 void set_xdap_protocol(int major, int minor);
00141
00148 void set_cookie_jar(const string &cookie_jar)
00149 {
00150 d_cookie_jar = cookie_jar;
00151 }
00152
00158 void set_cache_enabled(bool enabled)
00159 {
00160 if (d_http_cache)
00161 d_http_cache->set_cache_enabled(enabled);
00162 }
00163
00165 bool is_cache_enabled()
00166 {
00167 return (d_http_cache) ? d_http_cache->is_cache_enabled() : false;
00168 }
00169
00170 HTTPResponse *fetch_url(const string &url);
00171 };
00172
00173 }
00174
00175 #endif // _httpconnect_h