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>
33 using namespace xmltooling;
34 using namespace boost;
37 GenericRequest::GenericRequest()
41 GenericRequest::~GenericRequest()
45 HTTPRequest::HTTPRequest()
49 HTTPRequest::~HTTPRequest()
53 bool HTTPRequest::isSecure() const
55 return strcmp(getScheme(),"https")==0;
59 void handle_cookie_fn(map<string,string>& cookieMap, vector<string>& nvpair, const string& s) {
61 split(nvpair, s, is_any_of("="));
62 if (nvpair.size() == 2) {
64 cookieMap[nvpair[0]] = nvpair[1];
69 const char* HTTPRequest::getCookie(const char* name) const
71 if (m_cookieMap.empty()) {
72 string cookies=getHeader("Cookie");
73 vector<string> nvpairs, nvpair;
74 split(nvpairs, cookies, is_any_of(";"), algorithm::token_compress_on);
75 for_each(nvpairs.begin(), nvpairs.end(), boost::bind(handle_cookie_fn, boost::ref(m_cookieMap), boost::ref(nvpair), _1));
77 map<string,string>::const_iterator lookup=m_cookieMap.find(name);
78 return (lookup==m_cookieMap.end()) ? nullptr : lookup->second.c_str();