2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
24 * Interface to HTTP requests.
28 #include "HTTPRequest.h"
30 #include <boost/algorithm/string.hpp>
31 #include <boost/bind.hpp>
32 #include <boost/tokenizer.hpp>
34 using namespace xmltooling;
35 using namespace boost;
38 GenericRequest::GenericRequest()
42 GenericRequest::~GenericRequest()
46 HTTPRequest::HTTPRequest()
50 HTTPRequest::~HTTPRequest()
54 bool HTTPRequest::isSecure() const
56 return strcmp(getScheme(),"https")==0;
60 void handle_cookie_fn(map<string,string>& cookieMap, vector<string>& nvpair, const string& s) {
62 split(nvpair, s, is_any_of("="));
63 if (nvpair.size() == 2) {
65 cookieMap[nvpair[0]] = nvpair[1];
70 const char* HTTPRequest::getCookie(const char* name) const
72 if (m_cookieMap.empty()) {
73 string cookies=getHeader("Cookie");
74 vector<string> nvpair;
75 tokenizer< char_separator<char> > nvpairs(cookies, char_separator<char>(";"));
76 for_each(nvpairs.begin(), nvpairs.end(), boost::bind(handle_cookie_fn, boost::ref(m_cookieMap), boost::ref(nvpair), _1));
78 map<string,string>::const_iterator lookup=m_cookieMap.find(name);
79 return (lookup==m_cookieMap.end()) ? nullptr : lookup->second.c_str();