HTTPConnect.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#ifndef _httpconnect_h
#define _httpconnect_h
#include <string>
#include <curl/curl.h>
//No longer used in CURL - pwest April 09, 2012
//#include <curl/types.h>
#include <curl/easy.h>
#ifndef _rc_reader_h_
#include "RCReader.h"
#endif
#ifndef _object_type_h
#include "ObjectType.h"
#endif
#ifndef _http_cache_h
#include "HTTPCache.h"
#endif
#ifndef http_response_h
#include "HTTPResponse.h"
#endif
#ifndef _util_h
#include "util.h"
#endif
using std::string;
using std::vector;
namespace libdap
{
extern int www_trace;
extern int www_trace_extensive;
extern int dods_keep_temps;
class HTTPConnect
{
private:
CURL *d_curl;
RCReader *d_rcr;
HTTPCache *d_http_cache;
char d_error_buffer[CURL_ERROR_SIZE]; // A human-readable message.
std::string d_content_type; // apparently read by libcurl; this is valid only after curl_easy_perform()
bool d_accept_deflate;
string d_username; // extracted from URL
string d_password; // extracted from URL
string d_upstring; // used to pass info into curl
string d_cookie_jar;
vector<string> d_request_headers; // Request headers
int d_dap_client_protocol_major;
int d_dap_client_protocol_minor;
bool d_use_cpp_streams; // Build HTTPResponse objects using fstream and not FILE*
void www_lib_init();
long read_url(const string &url, FILE *stream, vector<string> *resp_hdrs,
const vector<string> *headers = 0);
HTTPResponse *plain_fetch_url(const string &url);
HTTPResponse *caching_fetch_url(const string &url);
bool url_uses_proxy_for(const string &url);
bool url_uses_no_proxy_for(const string &url) throw();
void extract_auth_info(string &url);
friend size_t save_raw_http_header(void *ptr, size_t size, size_t nmemb,
void *http_connect);
friend class HTTPConnectTest;
friend class ParseHeader;
protected:
HTTPConnect();
HTTPConnect(const HTTPConnect &);
HTTPConnect &operator=(const HTTPConnect &);
public:
HTTPConnect(RCReader *rcr, bool use_cpp = false);
virtual ~HTTPConnect();
void set_credentials(const string &u, const string &p);
void set_accept_deflate(bool defalte);
void set_xdap_protocol(int major, int minor);
bool use_cpp_streams() const { return d_use_cpp_streams; }
void set_use_cpp_streams(bool use_cpp_streams) { d_use_cpp_streams = use_cpp_streams; }
void set_cookie_jar(const string &cookie_jar) { d_cookie_jar = cookie_jar; }
void set_cache_enabled(bool enabled) {
if (d_http_cache)
d_http_cache->set_cache_enabled(enabled);
}
bool is_cache_enabled() { return (d_http_cache) ? d_http_cache->is_cache_enabled() : false; }
HTTPResponse *fetch_url(const string &url);
};
} // namespace libdap
#endif // _httpconnect_h
libdap::HTTPCache
Definition HTTPCache.h:104
libdap::HTTPCache::set_cache_enabled
void set_cache_enabled(bool mode)
Definition HTTPCache.cc:635
libdap::HTTPCache::is_cache_enabled
bool is_cache_enabled() const
Definition HTTPCache.cc:647
libdap::HTTPConnect
Definition HTTPConnect.h:74
libdap::HTTPConnect::set_accept_deflate
void set_accept_deflate(bool defalte)
Definition HTTPConnect.cc:1016
libdap::HTTPConnect::is_cache_enabled
bool is_cache_enabled()
Definition HTTPConnect.h:157
libdap::HTTPConnect::fetch_url
HTTPResponse * fetch_url(const string &url)
Definition HTTPConnect.cc:635
libdap::HTTPConnect::set_credentials
void set_credentials(const string &u, const string &p)
Definition HTTPConnect.cc:1081
libdap::HTTPConnect::set_cache_enabled
void set_cache_enabled(bool enabled)
Definition HTTPConnect.h:151
libdap::HTTPConnect::set_xdap_protocol
void set_xdap_protocol(int major, int minor)
Definition HTTPConnect.cc:1044
libdap::HTTPConnect::set_cookie_jar
void set_cookie_jar(const string &cookie_jar)
Definition HTTPConnect.h:144
libdap::HTTPResponse
Definition HTTPResponse.h:57
libdap::RCReader
Definition RCReader.h:55
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:36