Savarese Software Research Corporation
FCGIRequest.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2009 Savarese Software Research Corporation
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     https://www.savarese.com/software/ApacheLicense-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include <ssrc/wispers/fcgi/FCGIRequest.h>
00018 #include <ssrc/wispers/fcgi/URI.h>
00019 
00020 #include <sstream>
00021 
00022 __BEGIN_NS_SSRC_WSPR_FCGI
00023 
00024 const FCGIRequest::HTTPRequestMethodMap
00025 FCGIRequest::RequestMethodMap(&RequestMethodName[0],
00026                               &RequestMethodName[MethodNum]);
00027 
00037 void FCGIRequest::set_session_id() {
00038   const char *cookie_str =
00039     FCGI::FCGX_GetParam("HTTP_COOKIE", _fcgx_request->envp);
00040   /*
00041   if(cookie_str == 0 || *cookie_str == 0)
00042     cookie_str = FCGI::FCGX_GetParam("HTTP_COOKIE2", _fcgx_request->envp);
00043   */
00044   if(cookie_str && *cookie_str != 0) {
00045     const char *data = std::strstr(cookie_str, "WSPRSID=");
00046 
00047     if(data) {
00048       const char *end = std::strchr(data, ';');
00049 
00050       if(end) {
00051         _session_id.append(data, end - data + 8);
00052       } else {
00053         _session_id.append(data + 8);
00054       }
00055     }
00056   }
00057 }
00058 
00059 string FCGIRequest::to_absolute_url(const string & url) const
00060   SSRC_DECL_THROW(std::invalid_argument)
00061 {
00062   URI uri(url);
00063 
00064   if(uri.absolute())
00065     return url;
00066   else {
00067     std::ostringstream location;
00068 
00069     location << scheme() << "://" << server_name();
00070 
00071     int port = server_port();
00072      
00073     if((!https() && port != PORT_HTTP) || (https() && port != PORT_HTTPS))
00074       location << ':' << port;
00075 
00076     // Relative redirects treat the request uri as a directory.  We
00077     // could figure out if the uri refers to a directory or a file and
00078     // use the parent if a file, but this is sufficient for our needs.
00079     if(url[0] != '/')
00080       location << request_uri() << '/'; 
00081 
00082     location << url;
00083 
00084     return location.str();
00085   }
00086 }
00087 
00088 __END_NS_SSRC_WSPR_FCGI

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.