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 using namespace xmltooling;
33 GenericRequest::GenericRequest()
37 GenericRequest::~GenericRequest()
41 HTTPRequest::HTTPRequest()
45 HTTPRequest::~HTTPRequest()
49 bool HTTPRequest::isSecure() const
51 return strcmp(getScheme(),"https")==0;
54 const char* HTTPRequest::getCookie(const char* name) const
56 if (m_cookieMap.empty()) {
57 string cookies=getHeader("Cookie");
59 string::size_type pos=0,cname,namelen,val,vallen;
60 while (pos !=string::npos && pos < cookies.length()) {
61 while (isspace(cookies[pos])) pos++;
63 pos=cookies.find_first_of("=",pos);
64 if (pos == string::npos)
68 if (pos==cookies.length())
71 pos=cookies.find_first_of(";",pos);
72 if (pos != string::npos) {
75 m_cookieMap.insert(make_pair(cookies.substr(cname,namelen),cookies.substr(val,vallen)));
78 m_cookieMap.insert(make_pair(cookies.substr(cname,namelen),cookies.substr(val)));
81 map<string,string>::const_iterator lookup=m_cookieMap.find(name);
82 return (lookup==m_cookieMap.end()) ? nullptr : lookup->second.c_str();