40 #include <curl/curl.h>
43 #include <BESCatalogUtils.h>
44 #include <BESCatalogList.h>
45 #include <BESCatalog.h>
47 #include <TheBESKeys.h>
48 #include <BESInternalError.h>
49 #include <BESNotFoundError.h>
50 #include <BESSyntaxUserError.h>
53 #include "HttpNames.h"
54 #include "HttpUtils.h"
55 #include "ProxyConfig.h"
64 #define prolog string("HttpUtils::").append(__func__).append("() - ")
77 if (found && vals.size()) {
78 vector<string>::iterator i = vals.begin();
79 vector<string>::iterator e = vals.end();
81 size_t colon = (*i).find(
":");
82 if (colon == string::npos) {
83 string err = (string)
"Malformed " + HTTP_MIMELIST_KEY +
" " + (*i) +
84 " specified in the gateway configuration";
87 string mod = (*i).substr(0, colon);
88 string mime = (*i).substr(colon + 1);
89 mime_list[mod] = mime;
115 size_t fnpos = disp.find(
"filename");
116 if (fnpos != string::npos) {
119 size_t pos = disp.find(
"#", fnpos);
120 if (pos == string::npos) pos = disp.find(
"=", fnpos);
121 if (pos != string::npos) {
127 size_t sp = disp.find(
" ", pos);
128 if (pos != string::npos) {
130 filename = disp.substr(pos + 1, sp - pos - 1);
133 filename = disp.substr(pos + 1);
137 if (filename[0] ==
'"') {
138 filename = filename.substr(1);
140 if (filename[filename.length() - 1] ==
'"') {
141 filename = filename.substr(0, filename.length() - 1);
153 void get_type_from_content_type(
const string &ctype,
string &type)
155 BESDEBUG(MODULE, prolog <<
"BEGIN content-type: " << ctype << endl);
156 map<string,string> mime_list;
158 map<string, string>::iterator i = mime_list.begin();
159 map<string, string>::iterator e = mime_list.end();
161 for (; i != e && !done; i++) {
162 BESDEBUG(MODULE, prolog <<
"Comparing content type '" << ctype <<
"' against mime list element '" << (*i).second <<
"'" << endl);
163 BESDEBUG(MODULE, prolog <<
"first: " << (*i).first <<
" second: " << (*i).second << endl);
164 if ((*i).second == ctype) {
165 BESDEBUG(MODULE, prolog <<
"MATCH" << endl);
170 BESDEBUG(MODULE, prolog <<
"END" << endl);
173 void get_type_from_url(
const string &
url,
string &type) {
184 size_t max_redirects=0;
188 if (found && !value.empty()) {
189 std::istringstream(value) >> max_redirects;
192 max_redirects = HTTP_MAX_REDIRECTS_DEFAULT;
194 return max_redirects;
214 void HttpUtils::decompose_url(
const string target_url, map<string,string> &url_info)
219 size_t query_index = target_url.find_first_of(
"?");
220 BESDEBUG(MODULE, prolog <<
"query_index: " << query_index << endl);
221 if(query_index != string::npos){
222 query_string = target_url.substr(query_index+1);
223 url_base = target_url.substr(0,query_index);
226 url_base = target_url;
228 url_info.insert( std::pair<string,string>(HTTP_TARGET_URL_KEY,target_url));
229 BESDEBUG(MODULE, prolog << HTTP_TARGET_URL_KEY <<
": " << target_url << endl);
230 url_info.insert( std::pair<string,string>(HTTP_URL_BASE_KEY,url_base));
231 BESDEBUG(MODULE, prolog << HTTP_URL_BASE_KEY <<
": " << url_base << endl);
232 url_info.insert( std::pair<string,string>(HTTP_QUERY_STRING_KEY,query_string));
233 BESDEBUG(MODULE, prolog << HTTP_QUERY_STRING_KEY <<
": " << query_string << endl);
234 if(!query_string.empty()){
235 vector<string> records;
236 string delimiters =
"&";
238 vector<string>::iterator i = records.begin();
239 for(; i!=records.end(); i++){
240 size_t index = i->find(
'=');
241 if(index != string::npos) {
242 string key = i->substr(0, index);
243 string value = i->substr(index+1);
244 BESDEBUG(MODULE, prolog <<
"key: " << key <<
" value: " << value << endl);
245 url_info.insert( std::pair<string,string>(key,value));
251 stringstream unix_time;
253 url_info.insert( std::pair<string,string>(HTTP_INGEST_TIME_KEY,unix_time.str()));
static BESCatalogList * TheCatalogList()
Get the singleton BESCatalogList instance.
virtual BESCatalog * default_catalog() const
The the default catalog.
std::string get_handler_name(const std::string &item) const
Find the handler name that will process.
virtual BESCatalogUtils * get_catalog_utils() const
Get a pointer to the utilities, customized for this catalog.
error thrown if there is a user syntax error in the request or any other user error
static void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters="/")
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.
utility class for the HTTP catalog module
size_t load_max_redirects_from_keys()
void get_type_from_disposition(const string &disp, string &type)
void load_mime_list_from_keys(map< string, string > &mime_list)