当前位置: 首页>>代码示例>>C++>>正文


C++ HttpResponse::getConnection方法代码示例

本文整理汇总了C++中HttpResponse::getConnection方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpResponse::getConnection方法的具体用法?C++ HttpResponse::getConnection怎么用?C++ HttpResponse::getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpResponse的用法示例。


在下文中一共展示了HttpResponse::getConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handler

	void BoshBaseRequestHandler::handler(HttpRequest& request, HttpResponse& response){
	
		xml_document doc;
		xml_parse_result xmlResult = doc.load(request.getBody().c_str());

		if(!xmlResult && !doc.child("body")){
			response.response(BoshErrorBuilder::badRequest(xmlResult.description()), HttpResponse::OK, true);
			return;
		}

		xml_node body = doc.child("body");

		string domain = body.attribute("to").value();
		if(domain != "talk.sixin.com"){
			domain = "talk.m.renren.com";
		}
		if(!domain.empty()){
				response.getConnection()->setAttribute("serverDomain", domain);
		}
		string sessionId = body.attribute("sid").value();
		request.setSessionId(sessionId);

		request.setMsgNode(body);

		boshHandler(request, response);

	}
开发者ID:xiaoyu-real,项目名称:Test,代码行数:27,代码来源:BoshBaseRequestHandler.cpp

示例2: operator

void ProxyResourceHandler::operator()(BtpAction* action)
{
   // get request host
   HttpRequestHeader* hrh = action->getRequest()->getHeader();
   string host = hrh->getFieldValue("X-Forwarded-Host");
   if(host.length() == 0)
   {
      host = hrh->getFieldValue("Host");
   }

   // find a rule
   Rule* rule = findRule(action, host);
   if(rule == NULL)
   {
      // delegate to rest resource handler
      RestResourceHandler::operator()(action);
   }
   else
   {
      // get URL to proxy or redirect to
      UrlRef url = rule->url;

      // get url host
      string urlHost;
      HttpResponse* res = action->getResponse();
      bool secure = res->getConnection()->isSecure();

      // if URL has no host, reuse incoming host
      if(url->getHost().length() == 0)
      {
         urlHost = host;
      }
      // if URL has no port or uses a default port number, only use URL host
      else if(
         (url->getPort() == 0) ||
         (secure && url->getPort() == 443) ||
         (!secure && url->getPort() == 80))
      {
         urlHost = url->getHost();
      }
      // use URL host and port
      else
      {
         urlHost = url->getHostAndPort();
      }

      // handle 0.0.0.0 (any host) by replacing it with the request host
      if(strncmp(urlHost.c_str(), "0.0.0.0", 8) == 0)
      {
         // 0.0.0.0 is 8 chars long
         urlHost.replace(0, 8, host.substr(0, host.find(':')).c_str());
      }

      // rewrite the request path if it does not match URL path
      string path = hrh->getPath();
      if(strcmp(path.c_str(), url->getPath().c_str()) != 0)
      {
         // check for path wildcard
         if(strcmp(rule->path, "*") == 0)
         {
            // since a wildcard is used, prepend the URL path to the
            // resource (if the url path isn't '/')
            string urlPath = url->getPath();
            if(urlPath.length() > 1)
            {
               path.insert(0, url->getPath().c_str());
            }
         }
         else
         {
            // replace the part of the resource that matched the proxy
            // rule with the rewrite path from the proxy URL
            path.replace(0, strlen(rule->path), url->getPath().c_str());
         }
      }

      // do redirect if appropriate
      if(rule->type == Rule::Redirect)
      {
         // set response code
         HttpResponseHeader* header = res->getHeader();
         if(rule->permanent)
         {
            header->setStatus(301, "Moved Permanently");
         }
         else
         {
            header->setStatus(302, "Found");
         }

         // build new location url
         bool secure = res->getConnection()->isSecure();
         header->setField("Location", StringTools::format("%s://%s%s",
            secure ? "https" : "http", urlHost.c_str(), path.c_str()));
         action->sendResult();
      }
      // do proxy
      else if(rule->type == Rule::Proxy)
      {
         // get client-side request
//.........这里部分代码省略.........
开发者ID:digitalbazaar,项目名称:bitmunk,代码行数:101,代码来源:ProxyResourceHandler.cpp


注:本文中的HttpResponse::getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。