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"
56#include "ProxyConfig.h"
65#define prolog string("HttpUtils::").append(__func__).append("() - ")
78 if (found && vals.size()) {
79 vector<string>::iterator i = vals.begin();
80 vector<string>::iterator e = vals.end();
82 size_t colon = (*i).find(
":");
83 if (colon == string::npos) {
84 string err = (string)
"Malformed " + HTTP_MIMELIST_KEY +
" " + (*i) +
85 " specified in the gateway configuration";
88 string mod = (*i).substr(0, colon);
89 string mime = (*i).substr(colon + 1);
90 mime_list[mod] = mime;
116 size_t fnpos = disp.find(
"filename");
117 if (fnpos != string::npos) {
120 size_t pos = disp.find(
"#", fnpos);
121 if (pos == string::npos) pos = disp.find(
"=", fnpos);
122 if (pos != string::npos) {
128 size_t sp = disp.find(
" ", pos);
129 if (pos != string::npos) {
131 filename = disp.substr(pos + 1, sp - pos - 1);
134 filename = disp.substr(pos + 1);
148void get_type_from_content_type(
const string &ctype,
string &type)
150 BESDEBUG(MODULE, prolog <<
"BEGIN content-type: " << ctype << endl);
151 map<string,string> mime_list;
153 map<string, string>::iterator i = mime_list.begin();
154 map<string, string>::iterator e = mime_list.end();
156 for (; i != e && !done; i++) {
157 BESDEBUG(MODULE, prolog <<
"Comparing content type '" << ctype <<
"' against mime list element '" << (*i).second <<
"'" << endl);
158 BESDEBUG(MODULE, prolog <<
"first: " << (*i).first <<
" second: " << (*i).second << endl);
159 if ((*i).second == ctype) {
160 BESDEBUG(MODULE, prolog <<
"MATCH" << endl);
165 BESDEBUG(MODULE, prolog <<
"END" << endl);
168void get_type_from_url(
const string &
url,
string &type) {
179 size_t max_redirects=0;
183 if (found && !value.empty()) {
184 std::istringstream(value) >> max_redirects;
187 max_redirects = HTTP_MAX_REDIRECTS_DEFAULT;
189 return max_redirects;
209 void HttpUtils::decompose_url(
const string target_url, map<string,string> &url_info)
214 size_t query_index = target_url.find_first_of(
"?");
215 BESDEBUG(MODULE, prolog <<
"query_index: " << query_index << endl);
216 if(query_index != string::npos){
217 query_string = target_url.substr(query_index+1);
218 url_base = target_url.substr(0,query_index);
221 url_base = target_url;
223 url_info.insert( std::pair<string,string>(HTTP_TARGET_URL_KEY,target_url));
224 BESDEBUG(MODULE, prolog << HTTP_TARGET_URL_KEY <<
": " << target_url << endl);
225 url_info.insert( std::pair<string,string>(HTTP_URL_BASE_KEY,url_base));
226 BESDEBUG(MODULE, prolog << HTTP_URL_BASE_KEY <<
": " << url_base << endl);
227 url_info.insert( std::pair<string,string>(HTTP_QUERY_STRING_KEY,query_string));
228 BESDEBUG(MODULE, prolog << HTTP_QUERY_STRING_KEY <<
": " << query_string << endl);
229 if(!query_string.empty()){
230 vector<string> records;
231 string delimiters =
"&";
233 vector<string>::iterator i = records.begin();
234 for(; i!=records.end(); i++){
235 size_t index = i->find(
'=');
236 if(index != string::npos) {
237 string key = i->substr(0, index);
238 string value = i->substr(index+1);
239 BESDEBUG(MODULE, prolog <<
"key: " << key <<
" value: " << value << endl);
240 url_info.insert( std::pair<string,string>(key,value));
246 stringstream unix_time;
248 url_info.insert( std::pair<string,string>(HTTP_INGEST_TIME_KEY,unix_time.str()));
virtual BESCatalog * default_catalog() const
The the default catalog.
static BESCatalogList * TheCatalogList()
Get the singleton BESCatalogList instance.
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="/")
static void trim_if_surrounding_quotes(std::string &value)
Remove double quotes around a string This function will remove a leading and/or trailing double quote...
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)